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 [email protected]. 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= "[email protected]"; //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 [email protected]</p><br>";

}

?>

 

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

$mail_to= "[email protected]"; //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 [email protected]</p>
";
}
?>

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?

<?php
$mail_mesg="$Name<$mail_from> wrote: \n\n ".$_GET['Message']."";
$headers = "$mail_from \r\n Reply-To:$mail_from \r\n";?>

 

^ correct code you still need the dots for get message otherwise it wont work but it should parse the other variables

 

 

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 [email protected] ... 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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.