无法设置发件人名称phpmailer

时间:2016-04-12 11:06:39

标签: php phpmailer

所以我正在设置一个脚本,以便从联系我们表单发送电子邮件。除了我无法正确设置发件人姓名这一事实外,一切都很好。我收到一个错误:

Warning: Creating default object from empty value

我的代码如下所示:

<?php $eemail = $_REQUEST['email'] ;
 $message = $_REQUEST['message']; $subject = $_REQUEST['subject']; $fname =
 $_REQUEST['name'];

 require("class.phpmailer.php"); $mail = new PHPMailer();  

 $mail->Username = "email";  // SMTP username
 $mail->Password = "password"; // SMTP password  $mail->IsSMTP(); 
 $mail->SMTPAuth = true;  $mail->Host = 'aspmx.l.google.com'; 
 $mail->Port = 25;



 $mail->From = $eemail; $name->FromName = $fname; $mail->Subject =
 $subject;

 $mail->AddAddress("email", "name");


 $mail->WordWrap = 50;

 $mail->IsHTML(true);

 $mail->Body    = $message; $mail->AltBody = $message;

 if(!$mail->Send()) {    echo "Message could not be sent. <p>";    echo
 "Mailer Error: " . $mail->ErrorInfo;    exit; }

 echo "Message has been sent"; ?>

1 个答案:

答案 0 :(得分:0)

添加此代码

{{1}}