$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = "test.php@gmail.com";
$mail->Password = "****";
$mail->setFrom('test@email.com','duy tran');
收到的电子邮件显示来自:duytran gmail。 这意味着它使用用户名作为From email.must来自:duytran gmail 有没有建议解决它?
答案 0 :(得分:0)
您可以参考此代码,它将帮助您使用php Mailer类
$mail = new PHPMailer();
$to = "admin@gmail.com";
$mail->IsSendmail(); // telling the class to use SendMail transport
$from = $email;
$headers = "From: <".$from.">\n";
$headers .= "X-Sender: yourname<".$from.">\n";
$headers .= "X-Mailer: PHP\n"; // mailer
$headers .= "X-Priority: 1\n"; // Urgent message!
$headers .= "Return-Path: ".$from."\n"; // Return path for errors
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1\n"; // Mime type
$mailBody = "";
$mailBody = '<table cellpadding="4" cellspacing="0" border="0">
<tr>
<td valign="top" width="90px;">
<span>Listing For:</span>
</td>
<td valign="top">
'.$businessDetail['companyName'].'
</td>
</tr>
<tr>
<td valign="top" width="90px;">
<span>Listing Url:</span>
</td>
<td valign="top">
</td>
</tr>
<tr>
<td valign="top" width="90px;">
<span>Email:</span>
</td>
<td valign="top">
'.$email.'
</td>
</tr>
<tr>
<td valign="top" width="90px;">
<span>userName:</span>
</td>
<td valign="top">
'.$businessDetail['userName'].'
</td>
</tr>
<tr>
<td valign="top" width="90px;">
<span>Comment:</span>
</td>
<td valign="top">
'.$commentDesc.'
</td>
</tr>
</table>';
$mail->Subject = $mailSub;
$mail->IsHTML(true);
$mail->MsgHTML($mailBody);
$mail->SetFrom($email,'yourname');
$mail->AddAddress($to);
if($mail->Send()){
$variables['success'] = "posted successfully and email is send.";
}