Problem with php sendmail script

Hi,

I’m currently trying to personalize a theme I downloaded. It has a contact form with a php script for sending emails.

The emails don’t come through. I have used a basic php script to see whether my server was allowing php sendmail and that seems to work so there must be something wrong with the script itself although I don’t see it.

Any ideas?

Many thanks!

[php]<?php
if($_REQUEST[‘first_name’] == ‘’ || $_REQUEST[‘contact_email’] == ‘’ || $_REQUEST[‘message’] == ‘’):
return “error”;
endif;
if (filter_var($_REQUEST[‘contact_email’], FILTER_VALIDATE_EMAIL)):
$subject = ‘Contact from Webpage’; // Subject of your email

// Receiver email address
$to = ‘[email protected]’; //Change the email address by yours

// prepare header
$header = ‘From: ‘. $_REQUEST[‘first_name’] . " " .$_REQUEST[‘last_name’] . ’ <’. $_REQUEST[‘contact_email’] .’>’. “\r\n”;
$header .= ‘Reply-To: ‘. $_REQUEST[‘first_name’] . " " .$_REQUEST[‘last_name’] . ’ <’. $_REQUEST[‘contact_email’] .’>’. “\r\n”;
// $header .= 'Cc: ’ . ‘[email protected]’ . “\r\n”;
// $header .= 'Bcc: ’ . ‘[email protected]’ . “\r\n”;

$message .= 'Name: ’ . $_REQUEST[‘first_name’] . " " .$_REQUEST[‘last_name’] . “\n”;
$message .= 'Email: ’ . $_REQUEST[‘contact_email’] . “\n”;
$message .= 'Subject: ’ . $_REQUEST[‘contact_subject’] . “\n”;
$message .= 'Message: '. $_REQUEST[‘message’];

// Send contact information
mail($to, $subject, $message, $header);

echo ‘sent’;
else:
return “error”;
endif;

?>[/php]

Well, Moritz, a quick look at your code and it appears to be correct.

One small thing is that if you send an email with the same TO: and REPLY-TO:, some spam filters will drop it.
You should change the reply-to to your own address so that it does not match the person you are sending to.

Not sure if that is the issue or not, though. To debug the data being sent into your mail function, set up a
display to debug if they are correctly set up. You can do it this way: (Instead of just the mail command…)
[php]
echo “to: ***” . $to . “***
”;
echo “subject: ***” . $subject . “***
”;
echo “message: ***” . $message . “***
”;
die “headers: ***” . $header . “***”);
mail($to, $subject, $message, $header);
[/php]
This will show you exactly what you are sending into the mail() function. I add the stars to show up any
possible spaces that might be causing the $to or $header to fail. A space or special character will mess it
up. Since the PHP mail system is very simple, it is usually either just a problem with the $to’s formatting or
something that is causing the SPAM filter to waylay it…

Hope this helps…

Sponsor our Newsletter | Privacy Policy | Terms of Service