PHP MAILER:根用户从信息中取代
这个事件发生得如此随机,我不知道为什么。 看起来像这样的信息。
From: Root User < root@localhost.mydomain.com >
以下是我写的内容:
$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; }
我已经在这里使用try和catch方法。 任何人都可以透露为什么会发生这种情况? 我放弃了phpMailer吗?
请确保并设置发件人属性以及From和FromName属性。 另外,当您这样做时,请确保它是有效域的电子邮件地址,并带有MX和SPF记录。
如果没有设置发件人属性,sendmail将为服务器注入默认信息,通常是nobody@myserver.com或root@myserver.com
链接地址: http://www.djcxy.com/p/69333.html