Jump to content
Larry Ullman's Book Forums

Leaderboard


Popular Content

Showing content with the highest reputation since 03/29/20 in all areas

  1. 1 point
    Ok, the following is how I send emails from PHP. Uses PHPMailer. In XAMPP you need to tell it where your normal email connection is. $host = substr($_SERVER['HTTP_HOST'], 0, 5); if (in_array($host, array('127.0', '192.1', 'local'))) { $local = TRUE; // echo "Local is true, HOST is $host"; } else { $local = FALSE; // echo "Local is false, HOST is $host"; } if ($local) { // tests for using XAMPP locally ini_set('sendmail_from', 'your email address'); // needed for Win 10 localhost (Development) ini_set('SMTP', 'your email service SMTP server'); // needed for Win 10 localhost (Developmemt) } require './includes/PHPMailer/PHPMailerAutoload.php'; // available as a free download $mail = new PHPMailer(true); $mail->setFrom(EMAIL, 'Whoever'); $mail->addAddress(EMAIL, 'Whoeverr'); if ($local) $mail->Subject = 'The email subject'; else $mail->Subject = 'The email subject'; $mail->Body = 'The email body'; $mail->addAttachment($report_file); // optional if(!$mail->send()) { echo '<p>Message was not sent.</p>'; echo '<p>Mailer error: ' . $mail->ErrorInfo . '</p>'; } The EMAIL constant has the email address that I want to show the email was sent from/to - in this case the receiver and the sender are the same email address - just change them to whatever you want to use. Hope it helps. P.S., assumes that you are logged in to your email service. PPSS, I use PHPMailer as it lets you attach a file to an email if you want/need to.
×
×
  • Create New...