PHP邮件发送来自noreply@domail.com

时间:2016-01-04 16:27:43

标签: php email phpmailer

我想通过no-reply@mycompanmysname.com向点击我网站上的忘记密码链接的用户发送电子邮件。

我可以通过我公司的邮件服务器发送邮件,但我不希望显示我公司的电子邮件地址。 任何人都可以建议如何做到这一点?

我使用的是phpmailer,这是我的代码:

$from = "companyname@yahoo.com";
$mail = new PHPMailer();
$body             = $messageBody;
$mail->SMTPSecure = 'tls'; //added
$mail->SMTPAuth = true;
$mail->IsSMTP(); // telling the class to use SMTP
//$mail->SMTPDebug  = 2;                                                  
$mail->SMTPAuth   = true;                  
$mail->Host       = "smtp server name";    
$mail->Port       = 587;                   
$mail->Username   = "********"; 
$mail->Password   = "******";           
$mail->From("$name");
//$mail->SetFrom("$from");


$mail->MsgHTML($body);
$mail->AddAddress("$toEmail");
$mail->Subject = "".$subject."";$mail->Body = $headers . "<br>" . $messageBody . "<br>" . $confidential;
$mail->WordWrap = 50;
$mail->MsgHTML($mail->Body);

if(!$mail->Send()) {

    //echo "Mailer Error: " . $mail->ErrorInfo;
    print "<p class='Error'>Error in sending email.Please try again.</p>";

} else {
    print "<p class='success'>An email is sent to you with the access information.</p>";

}

1 个答案:

答案 0 :(得分:0)

their docs为例,您可以这样做:

//Set who the message is to be sent from
$mail->setFrom('from@example.com', 'First Last');
//Set an alternative reply-to address
$mail->addReplyTo('replyto@example.com', 'First Last');

从个人经验来看,你可以做到这一点并且有效,但在某些邮件客户端(例如Gmail)中,你会得到From: email@website.com via otherdomain.com的内容。除了添加一些DNS设置之外,我不确定是否还有其他方法。不确定你是否可以访问它。