php邮件发送者表单用户

php邮件发送者表单用户,php,phpmailer,Php,Phpmailer,我有phpmailer,我可以通过php页面发送电子邮件,没有任何问题 但发件人会自动通过用户名将其用于smtp服务器 我想从写邮件而不是默认发件人的用户处获取发件人电子邮件 这是表格代码 <?php require '../../PHPMailer/PHPMailer-master/PHPMailerAutoload.php'; $name = $_POST['name']; $Institute = $_POST['Institute']; $email = $_POST['email

我有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             = 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");
}

请尝试此代码。。。如果您使用的是来自Github的PHP Mailer, 然后您可以通过以下方式设置发件人名称:

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

谢谢我收到了电子邮件,但是setFrom from from Mygmail=用户名不是新的我收到了电子邮件ok。。。但是来自Gmail ID而不是来自fromemail@gmail.com. 我将此更改为我的第二封电子邮件,但仍然来自Gmail Idcomplete,请帮助我
$mail->SetFrom("info@mibckerala.org", "MIBC");