Jump to content

email CGI-Mailer


DezB1

Recommended Posts

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("mail@example.co.uk","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
Share on other sites

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: webmaster@example.com' . "\r\n" .
    'Reply-To: webmaster@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();


mail("mail@example.co.uk","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
Share on other sites

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