View Full Version : Problems with PHP form submission

11-12-2011, 06:10 PM

I have a form I have set up using php that should submit an email on completion. When I set it up and tested it on my own website it worked absolutely fine but now I have uploaded it to a different website it no longer sends the email even though I get no error messages. i have spoken to the hosting company who have advised Emails have to have a senders address specified in your code, the server will reject any other emails to prevent spam. But surely that's what this line of my code does:

$mailheader = "From: ".$_POST["email"]."\r\n";

doesn't it?

Can anyone help me please?

Full code supplied below



$securimage = new Securimage();
if($securimage->check($_POST['captcha_code']) == false) {
// The code was incorrect
echo "The security code entered was incorrect.<br /><br />";
echo "Please click back and try again.";

if($_POST["email"] != '') {
$ToEmail = '[myemailaddress]';
$EmailSubject = 'Online Course Enquiry';
$mailheader = "From: ".$_POST["email"]."\r\n";
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
$MESSAGE_BODY = "Name: ".$_POST["name"]."<br>";
$MESSAGE_BODY .= "Job Title: ".$_POST["job_title"]."<br>";
$MESSAGE_BODY .= "Company: ".$_POST["company"]."<br>";
$MESSAGE_BODY .= "Email: ".$_POST["email"]."<br>";
$MESSAGE_BODY .= "Address: ".nl2br($_POST["address"])."<br>";
$MESSAGE_BODY .= "Telephone: ".$_POST["phone"]."<br>";
$MESSAGE_BODY .= "Course Title: ".$_POST["course_title"]."<br>";
$MESSAGE_BODY .= "Course Date: ".$_POST["course_date"]."<br>";
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");
header('Location:http://www.rework.co.uk/trainingsche...ccess=1'); // Redirect on success
} else {
echo('Your email address was left blank. Please click back and type your email address.');

11-12-2011, 07:43 PM
But surely that's what this line of my code does:

<code>$mailheader = "From: ".$_POST["email"]."\r\n";</code>

I don't think so. You didn't post the code that calls this page so I don't knoe for sure, but I don't know why you would send YOUR email address from another page when you can hard code it so easily.

Replace ".$_POST["email"]." with YOUR return address. Also $ToEmail = '[myemailaddress]'; probably needs to be changed.

11-13-2011, 09:52 AM
Hi Sunfighter

thanks for your response, sorry that wasn't clear it was my way of not posting my email address!

$ToEmail = '[myemailaddress]'; does contain my actual email address in the real code instead of "myemailaddress" but I should also add it in to the line above, so it reads ".$_POST["jo@[domain].co.uk"]." is that what you're saying?

I guess the biggest thing I don't get is why it works okay as it was on my webserver but not on the new webserver!

11-14-2011, 08:45 AM
okay so with a little playing around I've managed to sort all my paths for the CAPTCHA and this is no longer causing an issue.

I now get confirmation that my form has submitted successfully and that works fine. However, I still don't get the actual email confirmation. I get this fine when tested on my own webserver just not on the clients. The client's hosting company say this is because the sender's email address needs to be specified by surely that's what this line of my code does:
<code>$mailheader = "From: ".$_POST["email"]."\r\n"; </code>

Does anyone have any other suggestions??

Many thanks for any assistance