2016-11-11 92 views
1

有沒有一種方法可以設置php的mail()函數使用的電子郵件地址,而不會被垃圾郵件過濾器捕獲?設置php郵件使用的電子郵件

如果我不添加郵件頭,那麼郵件將從[email protected]發送出去,這不是最差的名字,因爲大多數郵件服務只是縮短到Apache。但我希望這是noreply.mydomain.com如果我添加一個來自頭部並放置其他任何東西,它似乎總是被垃圾郵件抓住,但如果只是保持默認狀態,則不會。

我的設置是在Linux上的Amazon EC2微型

+0

ok我認爲@John Conde的標記是重複的,他的鏈接確實匹配。我應該刪除問題還是應該怎麼做? –

回答

0

你也可以使用的PHPMailer類在https://github.com/PHPMailer/PHPMailer PHP 7。

它允許您使用郵件功能或透明地使用smtp服務器。它還處理基於HTML的電子郵件和附件,因此您不必編寫自己的實現。

<?php 
require 'PHPMailerAutoload.php'; 

$mail = new PHPMailer; 

$mail->isSMTP();          // Set mailer to use SMTP 
$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers 
$mail->SMTPAuth = true;        // Enable SMTP authentication 
$mail->Username = '[email protected]';     // SMTP username 
$mail->Password = 'secret';       // SMTP password 
$mail->SMTPSecure = 'tls';       // Enable encryption, 'ssl' also accepted 

$mail->From = '[email protected]'; 
$mail->FromName = 'Mailer'; 
$mail->addAddress('[email protected]', 'Joe User');  // Add a recipient 
$mail->addAddress('[email protected]');    // Name is optional 
$mail->addReplyTo('[email protected]', 'Information'); 
$mail->addCC('[email protected]'); 
$mail->addBCC('[email protected]'); 

$mail->WordWrap = 50;         // Set word wrap to 50 characters 
$mail->addAttachment('/var/tmp/file.tar.gz');   // Add attachments 
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name 
$mail->isHTML(true);         // Set email format to HTML 

$mail->Subject = 'Here is the subject'; 
$mail->Body = 'This is the HTML message body <b>in bold!</b>'; 
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; 

if(!$mail->send()) { 
    echo 'Message could not be sent.'; 
    echo 'Mailer Error: ' . $mail->ErrorInfo; 
} else { 
    echo 'Message has been sent'; 
}