0
   Currentlt it shows the mail on which phpmailer SMTP is registered.

    $email='abc@email.com';
    $subjectRsc="Any";
    $message='Welcome';
    phpmail($email, $subjectRsc, $message);

My phpmailer function: 

 $mail = new PHPMailer;
    $mail->isSMTP();
    $mail->SMTPDebug = 0;
    $mail->SMTPAuth = true;
    $mail->Debugoutput = 'html';
    $mail->Host = 'smptp';
    $mail->Port = 465; // or 587
    $mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
    $mail->SMTPAuth = true;
    $mail->Username = PHP_MAILER_EMAIL;
    $mail->Password = PHP_MAILER_PASSWORD;
    $mail->AddReplyTo(REPLY_EMAIL, 'ABC');
    $mail->SetFrom(FROM_EMAIL, 'ABC');
    $mail->Subject = $subject;
    $address = $to;
    $mail->AddAddress($address);
    $mail->MsgHTML($message);
    //send the message, check for errors
    if (!$mail->send()) {
        echo "Mailer Error: " . $mail->ErrorInfo;
    } else {
        return true;
    }

This is how I am sending mails to the users I want to show the specific mail of my website to be displayed in the mails not that on which smtp server is registered.

Shahzaib
  • 33
  • 1
  • 11
  • Possible duplicate of [PHP E-mail Form Sender Name Instead Of E-mail?](https://stackoverflow.com/questions/6728361/php-e-mail-form-sender-name-instead-of-e-mail) – Farkie Nov 15 '18 at 08:27
  • Please include defitinition of function `phpmail()` as there is no such built-in php function. Are you using http://php.net/manual/en/function.mail.php internally? Or are you using some library such as PHPMailer? – Kyborek Nov 15 '18 at 08:27
  • Possible duplicate of [phpmailer change mail sender](https://stackoverflow.com/questions/27701411/phpmailer-change-mail-sender) – Oleg Nurutdinov Nov 15 '18 at 08:28
  • Are you using the library: _PHPMailer_ or Php's mail function 'mail', I can't find a reference for a function named: 'phpmail' that you have as your code sample. Confused. – Progrock Nov 15 '18 at 08:45
  • I am using phpmailer library – Shahzaib Nov 15 '18 at 08:57
  • Are you sending via a 3rd party mail server over SSL? Perhaps there is a restriction on your mail host (smtp server). As this looks like you are forging your from address. Do any emails get sent, and if so is your mailer ignoring your stated from address? Have you tried to debug this? You can view the transaction that Phpmailer makes with the 3rd party smtp server by turning on debugging. Check the manual. Lastly do you need to forge a from address? What's the point? – Progrock Nov 15 '18 at 09:56
  • what do u mean by forge a from address? – Shahzaib Nov 15 '18 at 13:34

3 Answers3

0

You should try this :

   $mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 0;
$mail->SMTPAuth = true;
$mail->Debugoutput = 'html';
$mail->Host = 'smptp';
$mail->Port = 465; // or 587
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
$mail->SMTPAuth = true;
$mail->Username = PHP_MAILER_EMAIL;
$mail->Password = PHP_MAILER_PASSWORD;
$mail->addReplyTo('myemail@example.com', 'ABC'); //<-- this is the line i changed
$mail->From= "myemail@example.com";  //<-- this is the line i changed
$mail->Subject = $subject;
$address = $to;
$mail->AddAddress($address);
$mail->MsgHTML($message);
//send the message, check for errors
if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    return true;
}

According to phpmailer documentation this is the field to add the sender's email.

pr1nc3
  • 8,108
  • 3
  • 23
  • 36
0
please try using this code  :

<?php

require_once "vendor/autoload.php";

//PHPMailer Object
$mail = new PHPMailer;

//From email address and name
$mail->From = "from@yourdomain.com";
$mail->FromName = "Full Name";

//To address and name
$mail->addAddress("test@gmail.com", "Test");
$mail->addAddress("test1@gmail.com"); 

//Address to which recipient will reply

//if you want to add CC and BCC
$mail->addCC("cc@example.com");
$mail->addBCC("bcc@example.com");

//Send HTML or Plain Text email
$mail->isHTML(true);

$mail->Subject = "Subject Text";
$mail->Body = "<i>Mail body in HTML</i>";
if(!$mail->send()) 
{
    echo "Mailer Error: " . $mail->ErrorInfo;
} 
else 
{
    echo "Message has been sent successfully";
}

?>
0

Please try using this code:

<?php

$to = "test@gmail.com";
     $subject = "This is subject";

     $message = "<b>This is HTML message.</b>";
     $message .= "<h1>This is headline.</h1>";

     $header = "From:test1@gmail.com \r\n";
   $header .= "Cc:test2@gmail \r\n";
     $header .= "MIME-Version: 1.0\r\n";
     $header .= "Content-type: text/html\r\n";

     $retval = mail ($to,$subject,$message,$header);

     if( $retval == true ) {
        echo "Message sent successfully...";
     }else {
        echo "Message could not be sent...";
     }

?>
bfontaine
  • 18,169
  • 13
  • 73
  • 107