2014-02-13 62 views
0

我有PHPMailer的,我可以通過PHP頁面沒有任何問題PHP的郵件發送形式的用戶

但發件人自動的用戶名是我在SMTP服務器使用

我想採取發件人的電子郵件用戶發送電子郵件誰寫的消息不是從默認的發件人

,這是形式的代碼

<?php 
require '../../PHPMailer/PHPMailer-master/PHPMailerAutoload.php'; 
$name = $_POST['name']; 
$Institute = $_POST['Institute']; 
$email = $_POST['email']; 
$message = $_POST['message']; 

$mail = new PHPMailer(); 
$mail->isSMTP(); 
$mail->CharSet = 'UTF-8'; 
$mail->Debugoutput = 'html'; 
//$mail->SMTPDebug = true; 
$mail->Host = 'smtp.gmail.com'; 
$mail->Port = 587; 
$mail->SMTPSecure = 'tls'; 
$mail->SMTPAuth = true; 
$mail->Username = "MyGmail"; 
$mail->Password = "MyGmailPass"; 
$mail->setFrom('Mygmail', $name); 
$mail->addReplyTo('MyGmail', 'First Last'); 
$mail->addAddress('MyEmail', 'Nasser'); 
$mail->Subject = 'Database Site Reminder'; 
$mail->Body = ($message); 
$mail->AltBody = 'This is a plain-text message body'; 
if (!$mail->send()) { 
    echo "Mailer Error: " . $mail->ErrorInfo; 
} else { 
    echo "Message sent!"; 
} 
?> 

我正在把`$ MAIL-> setFrom( 'Mygmail',$名);這就像

$mail->setFrom($email, $name); 

因爲採取發件人的電子郵件用戶,而我得到的消息發送 但消息沒有到達我的電子郵件

我找不到任何解決方案...請幫助我
感謝...

回答

0
$mail    = new PHPMailer(); 
$body    = "Body text goes here"; 
$mail->IsSMTP(); // telling the class to use SMTP 
$mail->Host  = "smtp.gmail.com"; // SMTP server 
$mail->SMTPDebug = 2;      // enables SMTP debug information (for testing) 
              // 1 = errors and messages 
              // 2 = messages only 
$mail->SMTPAuth = true;     // enable SMTP authentication 
$mail->SMTPSecure = "tls";     // sets the prefix to the servier 
$mail->Host  = "smtp.gmail.com";  // sets GMAIL as the SMTP server 
$mail->Port  = 587;     // set the SMTP port for the GMAIL server 
$mail->Username = "Gmail Id"; // GMAIL username 
$mail->Password = "PaSsWoRd";   // GMAIL password 
$mail->SetFrom('[email protected]', 'User'); 
$mail->AddReplyTo("[email protected]","User"); 
$mail->Subject = "Subject Goes Here"; 
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test 
$mail->MsgHTML($body); 
$mail->AddAddress('[email protected]', 'User'); 
if(!$mail->Send()) { 
    echo "Mailer Error: " . $mail->ErrorInfo; 
} else { 
    echo("Success"); 
} 

試試這個代碼...它的工作....

+0

感謝..我收到的電子郵件,但setFrom來自Mygmail =用戶名不遊記一個 – user3264926

+0

對不起,u能介紹一下.... – Rajesh

+0

我正在接收的電子郵件確定。 ..但從Gmail ID不是從[email protected]。我將此更改爲我的第二封電子郵件,但仍然來自Gmail ID – user3264926

0

如果從Github上使用PHP梅勒, 那麼你可以通過設置發件人的名字,

$mail->SetFrom("[email protected]", "MIBC");