Jump to content

[SOLVED] change from address in email sent from php script


gwood_25

Recommended Posts

Hello,

 

I have a strange problem that I'm not sure how to solve. I have a web form that collects name, email and message from users of my website. This info is posted to a php script which then emails the info to our email address.

 

The problem is, the from address never gets changed from webmaster@ourdomain.com. I haven't specified this address in the script at all and am adding extra headers to try and change the from address to the email addy specified by the user....here is my script. Any help is greatly appreciated.

 

<?php

header("Cache-Control: no-cache, must-revalidate");

 

$mail_to= "info@mysite.com"; //address I want the website emails going to

$Name =$_GET['Name'];

$mail_from=$_GET['Email'];

$mail_sub="Message from Wheatcity Cowtown Website";

$mail_mesg=$Name."<".$mail_from."> wrote: \n\n".$_GET['Message'];

$headers = $mail_from."\r\n"."Reply-To:".$mail_from."\r\n";

 

 

 

if(mail($mail_to,$mail_sub,$mail_mesg,$headers))

{

echo "<br><br><p align=center>E-mail has been sent successfully</p>";

}

else

{

echo "<br><br><p align=center>Failed to send the E-mail, please try again or contat us info@wheatcitycowtown.com</p><br>";

}

?>

 

Link to comment
Share on other sites

<?php
header("Cache-Control: no-cache, must-revalidate");

$mail_to= "info@mysite.com"; //address I want the website emails going to
$Name =$_GET['Name'];
$mail_from=$_GET['Email'];
$mail_sub="Message from Wheatcity Cowtown Website";
$mail_mesg=$Name"<"$mail_from"> wrote: \n\n"$_GET['Message'];
$headers = $mail_from"\r\n""Reply-To:"$mail_from"\r\n";



if(mail($mail_to,$mail_sub,$mail_mesg,$headers))
{
   echo "

<p align=center>E-mail has been sent successfully</p>";
}
else
{
   echo "

<p align=center>Failed to send the E-mail, please try again or contat us info@wheatcitycowtown.com</p>
";
}
?>

Link to comment
Share on other sites

removing the dots breaks the script. The dots are required for concatenation aren't they? Please bear with me I am very new to php and I am not sure what the issue is. I am able to send mail successfully with my original script, it just won't change the from address or teh reply to address. This site is hosted with yahoo and runs on a linux server does this make a difference?

Link to comment
Share on other sites

ok, but the original question still remains.... why won't the "from" address in my mail client appear as the email addy submitted via the web form. It always displays as info@domain.com ... I can't change it. The reason I want to change it is so that I can easily reply to a customer message without copying and pasting.

Link to comment
Share on other sites

the code i have and that you modified for me should work under normal circumstances, however, yahoo doesn't allow you to send email via script that has a return address who's domain is outside of your hosted domain. If the return address domain is outside of the hosted domain, a default return address is used instead. This is a yahoo specific setting and is inteded for anti-spam measures.

 

Thank you again for your help.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.