回复发件人phpmailer

时间:2017-11-24 23:02:17

标签: php email phpmailer

我可以向我的邮箱发送没有问题的电子邮件,但发件人总是我自己的电子邮件地址,我希望发件人是填写联系表格的人的实际电子邮件,所以我可以直接回复。< / p>

<?php

require 'phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer();
function SendMail($to, $from, $body, $mail)
{
$mail->SMTPOptions = array(
'ssl' => array(
    'verify_peer' => false,
    'verify_peer_name' => false,
    'allow_self_signed' => true
)
);
$mail->isSMTP();

$mail->Host = "smtp.office365.com";
$mail->Port = "587";
$mail->Username = "MY EMAIL ADDRESS HERE";
$mail->Password = "MY PASSWORD";
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
// Send the mail

$mail->From = "MY EMAIL ADDRESS HERE";
$mail->setFrom($from, "Contact Form Request");
$mail->AddAddress("MY EMAIL ADDRESS HERE", "Mick");
$mail->Subject = "Contact Form Request";
$mail->Body = $body;

if($mail->send())
{
    return true;
}else{
  var_dump($mail->ErrorInfo);
  die();
  return false;
}

}

if ($_POST["submit"]) {

$userDetails = array(
"sender" => $_POST['name'],
"senderEmail" => $_POST['email'],
"phone"       => $_POST['phone'],
"address1"    => $_POST['address1'],
"address2"    => $_POST['address2'],
"address3"    => $_POST['address3'],
"postcode"    => $_POST['postcode'],
"skipsize"    => $_POST['skipsize'],
"delivery"    => $_POST['delivery'],
"message"     => $_POST['message'],
"pickup"      => $_POST['pickup'],
);


$mailBody .= "Name: $userDetails[sender] \n";
$mailBody .= "Email: $userDetails[senderEmail] \n";
$mailBody .= "Phone Number: $userDetails[phone] \n";
$mailBody .= "Address: $userDetails[address1], $userDetails[address2], $userDetails[address3], $userDetails[$postcode] \n";
$mailBody .= "Phone Number: $userDetails[phone] \n";
$mailBody .= "Skip Size Wanted: $userDetails[skipsize] \n";
$mailBody .= "Delivery Date Wanted: $userDetails[delivery] \n";
$mailBody .= "Pick Up Date Wanted: $userDetails[pickup] \n";
$mailBody .= "Message: $userDetails[message] \n";

if(SendMail("stuart@foamymedia.com", $from, $mailBody, $mail))
{
    $thankYou="<p class='thankyou'>Thank you! Your message has been sent.</p>";

}else{

}

}

?>

我错过了什么?因为它一直困扰我,没有直接在线答案。

帮助会很棒

1 个答案:

答案 0 :(得分:0)

你真的不想这样做!它的伪造会导致SPF检查失败,从而导致您的邮件遭到退回或垃圾邮件过滤。

这样做:

$mail->From = "MY EMAIL ADDRESS HERE";
$mail->From = "MY NAME HERE";
if (!$mail->addReplyTo($_POST['email'])) {
    die('Invalid email address');
}

您正在使用旧版本的PHPMailer - Get the latest

此外,禁用TLS证书验证。 Office365 呈现无效证书 - 如果由于某些其他问题而导致其失败,例如您的ISP拦截并重定向您的SMTP流量,这是非常常见的。找出为什么它失败并使用您的ISP提供的发送机制 - 这可能会阻止您使用Office365地址,原因与您无法建立起来的地址相同你的提交者。

所有这些都在the contact form example provided with PHPMailer中得到证明。