如何避免PHPMailer的邮件被视为垃圾邮件?

时间:2015-08-01 13:54:17

标签: php email smtp phpmailer

我正在使用SMTP认证来使用PHPMailer。只有来自Gmail的已完成邮件才会发送邮件。

我是从联系页面$nume = firstName, $prenume = last-name, $telefon = phone, $email = email, $mesaj = message (translated)开始的。 如果完成的邮件(来自表单提交)是雅虎邮件,那么一切都会变成垃圾邮件。如果是Gmail,第一封邮件转到imbox,则响应会转到垃圾邮件。

这是代码:

$nume = $_POST['nume'];
$prenume = $_POST['prenume'];
$telefon =  $_POST['telefon'];
$emailT = $_POST['email'];
$mesaj = $_POST['mesaj'];

$mail = new PHPMailer;

$mail->isSMTP();                                      
$mail->Host = 'mail.iulianbesliu.ro';  
$mail->SMTPAuth = true;                             
$mail->Username = 'contact@iulianbesliu.ro';                 
$mail->Password = 'password';                                          
$mail->Port = 25; 

$mail->From = $emailT;
$mail->FromName = $nume;
$mail->addAddress('contact@iulianbesliu.ro');
$mail->AddCustomHeader('Reply-to:info@xpal.com'); 

$mail->Subject = 'Utilizator Site';
$mail->Body    = 'Nume: ' . $nume . ' ' . ' Data Eveniment: ' . $prenume . ' ' . 'telefon: ' . $telefon . "\r\n" . $mesaj;

if(!$mail->send()) {
    ?>
    <script>
        alertify.error("Message could not be sent.");
    </script>
    <?php
    //echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    ?>
   <script>
       alertify.success("Message has been sent");
   </script>
    <?php
}

$responseMail = new PHPMailer;
$responseMail->isSMTP();                                      
$responseMail->Host = 'mail.iulianbesliu.ro';  
$responseMail->SMTPAuth = true;                             
$responseMail->Username = 'contact@iulianbesliu.ro';                 
$responseMail->Password = 'password';                                              
$responseMail->Port = 25; 

$responseMail->From =  'contact@iulianbesliu.ro';
$responseMail->FromName = 'Iulian Besliu';
$responseMail->addAddress($emailT);
$responseMail->AddCustomHeader('Reply-to:info@xpal.com'); 

$responseMail->Subject = 'Utilizator Site';
$responseMail->Body    = 'Buna ziua dl/dna ' . $nume . "\r\n" . 'Va multumim pentru interesul acordat in vizualizarea paginii noastre, mesajul dumneavoastra a fost inregistrat si vom revenii cu un raspuns in cel mai scurt timp posibil !' . "\r\n" . 'Toate cele bune,' . "\r\n" . 'Iulian B`enter code here`esliu';
$responseMail->send();

1 个答案:

答案 0 :(得分:0)

您正在伪造from地址,这将确保向Yahoo发送失败。将您自己的地址和提交者的地址放在回复中,如下所示:

$mail->From = 'contact@iulianbesliu.ro';
$mail->addReplyTo($emailT, $nume);

让PHPMailer处理回复标题,不要自己添加。

确保您自己的SPF和DKIM记录正确无误,并使用DKIM签署您的消息,尤其是雅虎,这也是一个好主意。

您的邮件服务器是否确实在没有加密的情况下使用身份验证?