2016-03-04 26 views
-2

我使用PHP郵件功能發送電子郵件。但是當我發送電子郵件時,我在表格標題" [email protected] via blue.truehostdns.com "中得到這個。當我發送電子郵件使用PHP郵件功能,然後進入表頭[email protected]通過asd.com

這是我的代碼:

$from="info <[email protected]>"; 
$headers = "MIME-Version: 1.0\r\n"; 
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
$headers .= 'From: ' . $from . "\r\n"; 
mail('[email protected]','NoReply', $clent_emailbody,$headers); 

如何從我的電子郵件中刪除我的託管服務提供商域(blue.truehostdns.com)?

+1

可能的重複http://stackoverflow.com/questions/8236312/how-to-remove-via-and-server-name-when-sending-mails-with-php –

回答

1

你應該使用PHPMailer的,這將是更容易完成你正在尋找這樣

require('PHPMailer.php'); 
$mail = new PHPMailer; 
    //$mail->SMTPDebug = 3;        // Enable verbose debug output 

    $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 TLS encryption, `ssl` also accepted 
    $mail->Port = 587;         // TCP port to connect to 

    $mail->setFrom('[email protected]', '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->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'; 
    } 

有了這個就應該是這樣的:

From : Mailer ([email protected]) 
To : Joe User ([email protected]) , [email protected] 
Object : Here is the subject 
------------------------------------------------------ 
This is the HTML message body <b>in bold!</b> 

如果你打的答覆,它會自動回覆郵件

您可以在這裏找到PHPMailer:https://github.com/PHPMailer/PHPMailer

+1

很好的建議,但使用[最新的版本](https://github.com/PHPMailer/PHPMailer)和示例代碼。 – Synchro

+1

謝謝,我想這已經有一段時間了,因爲我沒有用phpmailer發郵件haha 我會用正確的信息編輯 –

+0

這應該是一個完整且正確的答案! –

相關問題