这个事件是随机发生的,我不知道为什么。出现的信息如下所示。
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吗?
答案 0 :(得分:2)
确保并设置Sender属性以及From和FromName属性。此外,当您这样做时,请确保它是有效域的电子邮件地址,并带有MX和SPF记录。
如果未设置Sender属性,sendmail将为服务器注入带有默认信息的标头,通常类似于nobody@myserver.com或root@myserver.com