PHP MAILER: Root User replace From Information
This event happens so randomly and I have no clue as to why. Information that appears looks like this.
From: Root User < root@localhost.mydomain.com >
Below is a snippet of what I wrote:
$frtname = (!empty($_POST['frtname'])? mysql_real_escape_string($_POST['frtname']) :null); $lstname = (!empty($_POST['lstname'])? mysql_real_escape_string($_POST['lstname']) :null); $email = (!empty($_POST['email'])? mysql_real_escape_string($_POST['email']) :null); $message=$body; $new_recipient = array( 'user@email.com' => 'User Name', 'user1@email.com' => 'User Name 1' ); require_once ('phpMailer/class.phpmailer.php'); try{ $mail = new PHPMailer(); $mail->SetLanguage("en",'phpMailer/language/'); $mail->Priority = 1; $mail->SetFrom(stripcslashes($email), stripcslashes($frtname." ".$lstname), true); $mail->AddReplyTo(stripcslashes($email), stripcslashes($frtname." ".$lstname)); foreach($new_recipient as $email => $name){ $email = str_replace("'", "", $email); $name = str_replace("'", "", $name); $mail->AddAddress($email, $name); } $mail->Subject = stripcslashes($subject); $mail->MsgHTML(stripcslashes($message)); $mail->AltBody = 'This email is best view as HTML format.'; if(!$mail->Send()) { echo "Mailer Error: " . $mail->ErrorInfo; } else { echo "Message sent!"; $message="Your information was received, click ok to continue"; } $mail->ClearAddresses(); $mail->ClearAttachments(); }catch(phpmailerException $e){ echo $e->errorMessage(); $message = "Your message was not sent. Please try again."; }catch(Exception $e){ echo $e->getMessage(); exit; }
I am already using a try and catch method here. Can anyone give an insight as to why this is happening? Do i give up on phpMailer?
Be sure and set the Sender property, as well as the From and FromName properties. Also, when you do that, make sure it's an email address for a valid domain, with an MX and SPF record.
If the Sender property isn't set, sendmail will inject the header with the default info for the server, usually something like nobody@myserver.com or root@myserver.com
链接地址: http://www.djcxy.com/p/69334.html下一篇: PHP MAILER:根用户从信息中取代