php邮件发件人表单用户

时间:2014-02-13 05:57:26

标签: php phpmailer

我有phpmailer,我可以通过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-&gt; setFrom('Mygmail',$ name);这就像

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

因为从用户那里收发件邮件,我收到了邮件 但邮件未到达我的电子邮件

我找不到任何解决方案......请帮助我 谢谢...

2 个答案:

答案 0 :(得分: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('fromemail@gmail.com', 'User');
$mail->AddReplyTo("fromemail@gmail.com","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('toemail@gmail.com', 'User');
if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
   echo("Success");
}

试试这段代码......它的工作......

答案 1 :(得分:0)

如果您使用的是来自Github的PHP Mailer, 然后你可以设置发件人名称,

$mail->SetFrom("info@mibckerala.org", "MIBC");