DezB1 Posted May 1, 2015 Share Posted May 1, 2015 Hi Folks I'm relatively new to PHP so please excuse my ignorance where it shows through. I have a contact form on a website that sends perfectly well but when it is received the "From" box shows "CGI-Mailer" I would like to replace that with the senders email address that they have to enter on the contact form if at all possible. The code I am using is: <?php $where_form_is="http://".$_SERVER['SERVER_NAME'].strrev(strstr(strrev($_SERVER['PHP_SELF']),"/")); session_start(); if( ($_SESSION['security_code']==$_POST['security_code']) && (!empty($_POST['security_code'])) ) { mail("[email protected]","Blah Blah - Website Contact","Contact Form Data: Title: " . $_POST['field_1'] . " First Name: " . $_POST['field_2'] . " Last Name: " . $_POST['field_3'] . " Your email address: " . $_POST['field_4'] . " Your phone number: " . $_POST['field_5'] . " Message: " . $_POST['field_6'] . " "); include("confirm.html"); } else { echo "Invalid Captcha String."; } ?> Any help would be most appreciated, thank you DezB1 Link to comment https://forums.phpfreaks.com/topic/296009-email-cgi-mailer/ Share on other sites More sharing options...
gizmola Posted May 1, 2015 Share Posted May 1, 2015 This information comes from the php manual for mail here -> http://php.net/manual/en/function.mail.php. Did you read that? $headers = 'From: ' . $_POST['field_4'] . "\r\n" . 'Reply-To: ' . $_POST['field_4'] . "\r\n" . 'X-Mailer: PHP/' . phpversion(); These additional headers can be sent as an optional parameter to mail(). So your code would probably be: $headers = 'From: [email protected]' . "\r\n" . 'Reply-To: [email protected]' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail("[email protected]","Blah Blah - Website Contact","Contact Form Data: Title: " . $_POST['field_1'] . " First Name: " . $_POST['field_2'] . " Last Name: " . $_POST['field_3'] . " Your email address: " . $_POST['field_4'] . " Your phone number: " . $_POST['field_5'] . " Message: " . $_POST['field_6'] . " ", $headers); Link to comment https://forums.phpfreaks.com/topic/296009-email-cgi-mailer/#findComment-1510526 Share on other sites More sharing options...
DezB1 Posted May 1, 2015 Author Share Posted May 1, 2015 Hi Gizmola Thanks for getting back to me, I did read through the instructions especially example 2 but having tried several times I could not get it to work for some reason. I'll try your suggestion and see what happens. Regards DezB1 Link to comment https://forums.phpfreaks.com/topic/296009-email-cgi-mailer/#findComment-1510530 Share on other sites More sharing options...
jcbones Posted May 1, 2015 Share Posted May 1, 2015 On a side note, you need to check with your host. A lot of host will not send the mail unless it is FROM an address on the server. Link to comment https://forums.phpfreaks.com/topic/296009-email-cgi-mailer/#findComment-1510556 Share on other sites More sharing options...
DezB1 Posted May 3, 2015 Author Share Posted May 3, 2015 Hi Folks Worked a treat, many thanks again for your help. Regards DezB1 Link to comment https://forums.phpfreaks.com/topic/296009-email-cgi-mailer/#findComment-1510647 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.