0
votes

i have phpmailer and i can send email via php page without any problem

but the sender automatically by username it i am use in smtp server

i want take sender email from user who write message not from default sender

and this is form code

<?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!";
}
?>

i am put `$mail->setFrom('Mygmail', $name); this like

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

because take sender email from user , and i get Message sent but message not arrive to my email

i cant find any solution... please assist me
thanks ...

2

2 Answers

0
votes
$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");
}

try this code... its working....

0
votes

If you are using PHP Mailer from Github, then you can set the Sender name by,

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