Page 1 of 1

Question about my Mail Code..

Posted: Wed Dec 09, 2009 2:35 pm
by alfugazi
Ok here's the deal. I have a contact form that people use to email a client on a site.
There are a few fields on the page that are required to be input - Name, Email Address, Phone Number, and of course the Message itself.

This script works great but whats happening is when the email message arrives at its destination, it says it is coming from a default mail server from network solutions (where site is hosted). I'd like to see the inputted email address come up in the Network Solutions email program as the from email address as opposed to the network solutions default mail server email.

Can anyone help me out with this? I am very new to PHP and any help would be greatly appreciated.

<?php
$show_confirmation = false;
if(isset($_POST['action']) && $_POST['action'] == 'send') {

/* Set this variable to the email address you want the form to be submitted to: */
$to_email = 'info@ccestatemanagement.com';


/* Set this variable to be the Subject of the email that is received with the form submission. */
$subject = "CCEM Contact Form Submission";

/* Set this to be the text you want displayed to the user after they submit the form: */
$confirmation_text = "Your information has been sent. Thank You.";


$isOk=true;
if(!isset($_POST['name']) || preg_match("/^\s*$/", $_POST['name']) ) {
$bad_name=true;
$isOk = false;
}
if(!isset($_POST['email']) || preg_match("/^\s*$/", $_POST['email']) ) {
$bad_email=true;
$isOk = false;
}
if(!isset($_POST['phone']) || preg_match("/^\s*$/", $_POST['phone']) ) {
$bad_phone=true;
$isOk = false;
}

if($isOk) {
$message = "Contact Form Submission Details:\n==================================\n";
$message .= "Name:\t".$_POST['name']."\n";
$message .= "Email:\t".$_POST['email']."\n";
$message .= "Phone:\t".$_POST['phone']."\n";

if(isset($_POST['message'])) {
$message .= "Message:\t".$_POST['message']."\n";
}

mail($to_email, $subject, $message);
}

$show_confirmation = $isOk;
}
?>

Re: Question about my Mail Code..

Posted: Wed Dec 09, 2009 3:27 pm
by requinix
Take a look at the $additional_headers argument to mail. Check the examples and user comments.

Re: Question about my Mail Code..

Posted: Wed Dec 09, 2009 3:39 pm
by alfugazi
Tas...I understand the concept but dont really understand the syntax. Not sure how to take something a user inputs as an email address and then set a variable to that email address. I am learning still.

Re: Question about my Mail Code..

Posted: Wed Dec 09, 2009 4:02 pm
by AbraCadaver

Code: Select all

$headers = 'From: ' . $_POST['name'] . '<' . $_POST['email'] . '>' . "\r\n";