How to change email sender email in PHP Mailer












-1















   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.










share|improve this question

























  • Possible duplicate of PHP E-mail Form Sender Name Instead Of E-mail?

    – Farkie
    Nov 15 '18 at 8:27











  • Please include defitinition of function phpmail() as there is no such built-in php function. Are you using php.net/manual/en/function.mail.php internally? Or are you using some library such as PHPMailer?

    – Kyborek
    Nov 15 '18 at 8:27











  • Possible duplicate of phpmailer change mail sender

    – Oleg Nurutdinov
    Nov 15 '18 at 8: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 8:45













  • I am using phpmailer library

    – Shahzaib
    Nov 15 '18 at 8:57
















-1















   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.










share|improve this question

























  • Possible duplicate of PHP E-mail Form Sender Name Instead Of E-mail?

    – Farkie
    Nov 15 '18 at 8:27











  • Please include defitinition of function phpmail() as there is no such built-in php function. Are you using php.net/manual/en/function.mail.php internally? Or are you using some library such as PHPMailer?

    – Kyborek
    Nov 15 '18 at 8:27











  • Possible duplicate of phpmailer change mail sender

    – Oleg Nurutdinov
    Nov 15 '18 at 8: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 8:45













  • I am using phpmailer library

    – Shahzaib
    Nov 15 '18 at 8:57














-1












-1








-1








   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.










share|improve this question
















   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.







php smtp phpmailer






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 9:19







Shahzaib

















asked Nov 15 '18 at 8:24









ShahzaibShahzaib

89




89













  • Possible duplicate of PHP E-mail Form Sender Name Instead Of E-mail?

    – Farkie
    Nov 15 '18 at 8:27











  • Please include defitinition of function phpmail() as there is no such built-in php function. Are you using php.net/manual/en/function.mail.php internally? Or are you using some library such as PHPMailer?

    – Kyborek
    Nov 15 '18 at 8:27











  • Possible duplicate of phpmailer change mail sender

    – Oleg Nurutdinov
    Nov 15 '18 at 8: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 8:45













  • I am using phpmailer library

    – Shahzaib
    Nov 15 '18 at 8:57



















  • Possible duplicate of PHP E-mail Form Sender Name Instead Of E-mail?

    – Farkie
    Nov 15 '18 at 8:27











  • Please include defitinition of function phpmail() as there is no such built-in php function. Are you using php.net/manual/en/function.mail.php internally? Or are you using some library such as PHPMailer?

    – Kyborek
    Nov 15 '18 at 8:27











  • Possible duplicate of phpmailer change mail sender

    – Oleg Nurutdinov
    Nov 15 '18 at 8: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 8:45













  • I am using phpmailer library

    – Shahzaib
    Nov 15 '18 at 8:57

















Possible duplicate of PHP E-mail Form Sender Name Instead Of E-mail?

– Farkie
Nov 15 '18 at 8:27





Possible duplicate of PHP E-mail Form Sender Name Instead Of E-mail?

– Farkie
Nov 15 '18 at 8:27













Please include defitinition of function phpmail() as there is no such built-in php function. Are you using php.net/manual/en/function.mail.php internally? Or are you using some library such as PHPMailer?

– Kyborek
Nov 15 '18 at 8:27





Please include defitinition of function phpmail() as there is no such built-in php function. Are you using php.net/manual/en/function.mail.php internally? Or are you using some library such as PHPMailer?

– Kyborek
Nov 15 '18 at 8:27













Possible duplicate of phpmailer change mail sender

– Oleg Nurutdinov
Nov 15 '18 at 8:28





Possible duplicate of phpmailer change mail sender

– Oleg Nurutdinov
Nov 15 '18 at 8: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 8:45







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 8:45















I am using phpmailer library

– Shahzaib
Nov 15 '18 at 8:57





I am using phpmailer library

– Shahzaib
Nov 15 '18 at 8:57












3 Answers
3






active

oldest

votes


















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.






share|improve this answer


























  • I am not using mail function, I am using php mailer phpmail function

    – Shahzaib
    Nov 15 '18 at 8:57











  • phpmail function is not user in phpmailer library. Is it a custom function you created? phpmailer send email with $mail->send(); where in $mail is your array with all the info to be send.

    – pr1nc3
    Nov 15 '18 at 8:58













  • yes you are right

    – Shahzaib
    Nov 15 '18 at 9:10











  • Then can you provide your phpmail function? The problem you are trying to solve is there. Just edit your question.

    – pr1nc3
    Nov 15 '18 at 9:11













  • I have edited my question check now

    – Shahzaib
    Nov 15 '18 at 9:20



















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

?>





share|improve this answer
























  • not working only FromName is working

    – Shahzaib
    Nov 15 '18 at 10:48



















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 rn";
$header .= "Cc:test2@gmail rn";
$header .= "MIME-Version: 1.0rn";
$header .= "Content-type: text/htmlrn";

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

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

?>





share|improve this answer


























  • I achieve this by changing my smtp email

    – Shahzaib
    Dec 19 '18 at 7:59











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53315115%2fhow-to-change-email-sender-email-in-php-mailer%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes









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.






share|improve this answer


























  • I am not using mail function, I am using php mailer phpmail function

    – Shahzaib
    Nov 15 '18 at 8:57











  • phpmail function is not user in phpmailer library. Is it a custom function you created? phpmailer send email with $mail->send(); where in $mail is your array with all the info to be send.

    – pr1nc3
    Nov 15 '18 at 8:58













  • yes you are right

    – Shahzaib
    Nov 15 '18 at 9:10











  • Then can you provide your phpmail function? The problem you are trying to solve is there. Just edit your question.

    – pr1nc3
    Nov 15 '18 at 9:11













  • I have edited my question check now

    – Shahzaib
    Nov 15 '18 at 9:20
















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.






share|improve this answer


























  • I am not using mail function, I am using php mailer phpmail function

    – Shahzaib
    Nov 15 '18 at 8:57











  • phpmail function is not user in phpmailer library. Is it a custom function you created? phpmailer send email with $mail->send(); where in $mail is your array with all the info to be send.

    – pr1nc3
    Nov 15 '18 at 8:58













  • yes you are right

    – Shahzaib
    Nov 15 '18 at 9:10











  • Then can you provide your phpmail function? The problem you are trying to solve is there. Just edit your question.

    – pr1nc3
    Nov 15 '18 at 9:11













  • I have edited my question check now

    – Shahzaib
    Nov 15 '18 at 9:20














0












0








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.






share|improve this answer















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.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 15 '18 at 9:53

























answered Nov 15 '18 at 8:28









pr1nc3pr1nc3

4,2192723




4,2192723













  • I am not using mail function, I am using php mailer phpmail function

    – Shahzaib
    Nov 15 '18 at 8:57











  • phpmail function is not user in phpmailer library. Is it a custom function you created? phpmailer send email with $mail->send(); where in $mail is your array with all the info to be send.

    – pr1nc3
    Nov 15 '18 at 8:58













  • yes you are right

    – Shahzaib
    Nov 15 '18 at 9:10











  • Then can you provide your phpmail function? The problem you are trying to solve is there. Just edit your question.

    – pr1nc3
    Nov 15 '18 at 9:11













  • I have edited my question check now

    – Shahzaib
    Nov 15 '18 at 9:20



















  • I am not using mail function, I am using php mailer phpmail function

    – Shahzaib
    Nov 15 '18 at 8:57











  • phpmail function is not user in phpmailer library. Is it a custom function you created? phpmailer send email with $mail->send(); where in $mail is your array with all the info to be send.

    – pr1nc3
    Nov 15 '18 at 8:58













  • yes you are right

    – Shahzaib
    Nov 15 '18 at 9:10











  • Then can you provide your phpmail function? The problem you are trying to solve is there. Just edit your question.

    – pr1nc3
    Nov 15 '18 at 9:11













  • I have edited my question check now

    – Shahzaib
    Nov 15 '18 at 9:20

















I am not using mail function, I am using php mailer phpmail function

– Shahzaib
Nov 15 '18 at 8:57





I am not using mail function, I am using php mailer phpmail function

– Shahzaib
Nov 15 '18 at 8:57













phpmail function is not user in phpmailer library. Is it a custom function you created? phpmailer send email with $mail->send(); where in $mail is your array with all the info to be send.

– pr1nc3
Nov 15 '18 at 8:58







phpmail function is not user in phpmailer library. Is it a custom function you created? phpmailer send email with $mail->send(); where in $mail is your array with all the info to be send.

– pr1nc3
Nov 15 '18 at 8:58















yes you are right

– Shahzaib
Nov 15 '18 at 9:10





yes you are right

– Shahzaib
Nov 15 '18 at 9:10













Then can you provide your phpmail function? The problem you are trying to solve is there. Just edit your question.

– pr1nc3
Nov 15 '18 at 9:11







Then can you provide your phpmail function? The problem you are trying to solve is there. Just edit your question.

– pr1nc3
Nov 15 '18 at 9:11















I have edited my question check now

– Shahzaib
Nov 15 '18 at 9:20





I have edited my question check now

– Shahzaib
Nov 15 '18 at 9:20













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

?>





share|improve this answer
























  • not working only FromName is working

    – Shahzaib
    Nov 15 '18 at 10:48
















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

?>





share|improve this answer
























  • not working only FromName is working

    – Shahzaib
    Nov 15 '18 at 10:48














0












0








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

?>





share|improve this answer













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

?>






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 15 '18 at 10:12









Atul AkabariAtul Akabari

954




954













  • not working only FromName is working

    – Shahzaib
    Nov 15 '18 at 10:48



















  • not working only FromName is working

    – Shahzaib
    Nov 15 '18 at 10:48

















not working only FromName is working

– Shahzaib
Nov 15 '18 at 10:48





not working only FromName is working

– Shahzaib
Nov 15 '18 at 10:48











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 rn";
$header .= "Cc:test2@gmail rn";
$header .= "MIME-Version: 1.0rn";
$header .= "Content-type: text/htmlrn";

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

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

?>





share|improve this answer


























  • I achieve this by changing my smtp email

    – Shahzaib
    Dec 19 '18 at 7:59
















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 rn";
$header .= "Cc:test2@gmail rn";
$header .= "MIME-Version: 1.0rn";
$header .= "Content-type: text/htmlrn";

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

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

?>





share|improve this answer


























  • I achieve this by changing my smtp email

    – Shahzaib
    Dec 19 '18 at 7:59














0












0








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 rn";
$header .= "Cc:test2@gmail rn";
$header .= "MIME-Version: 1.0rn";
$header .= "Content-type: text/htmlrn";

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

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

?>





share|improve this answer















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 rn";
$header .= "Cc:test2@gmail rn";
$header .= "MIME-Version: 1.0rn";
$header .= "Content-type: text/htmlrn";

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

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

?>






share|improve this answer














share|improve this answer



share|improve this answer








edited Dec 19 '18 at 8:54









bfontaine

9,20874373




9,20874373










answered Nov 15 '18 at 11:18









Atul AkabariAtul Akabari

954




954













  • I achieve this by changing my smtp email

    – Shahzaib
    Dec 19 '18 at 7:59



















  • I achieve this by changing my smtp email

    – Shahzaib
    Dec 19 '18 at 7:59

















I achieve this by changing my smtp email

– Shahzaib
Dec 19 '18 at 7:59





I achieve this by changing my smtp email

– Shahzaib
Dec 19 '18 at 7:59


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53315115%2fhow-to-change-email-sender-email-in-php-mailer%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

List item for chat from Array inside array React Native

Thiostrepton

Caerphilly