Page 1 of 1

PHP mail script and Go Daddy

Posted: Fri Jun 04, 2010 8:58 am
by dtylerroberts
I have a client who hosts with Go Daddy and I have been messing with this email script for days trying to get it to work. The weird thing is that it will send an email if I remove the line

Code: Select all

$email_message .= "<tr><td> Email: /td td" . $email . "</td></tr>";
If I include that line in the script, the email never sends, but the correct message is returned, "your message has been sent ...". It could be something I've overlooked because I'm still relatively new to php. Any help would be greatly appreciated, this is driving me crazy and Go Daddy is no help at all. Here is my full code:

Code: Select all

//Start session
session_start();

//Validation error flag
$errflag = false;

//Function to sanitize values received from the form. Prevents SQL injection
function clean($str) {
$str = @trim($str);
if(get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
$headers = array(
"/to\:/i",
"/from\:/i",
"/bcc\:/i",
"/cc\:/i",
"/Content\-Transfer\-Encoding\:/i",
"/Content\-Type\:/i",
"/Mime\-Version\:/i"
);
$str = preg_replace($headers, '', $str);
return strip_tags($str);
return mysql_real_escape_string($str);
}

//Sanitize the POST values
$name = clean($_POST['name']);
$company = clean($_POST['company']);
$email = clean($_POST['email']);
$phone = clean($_POST['phone']);
$type = clean($_POST['type']);
$size = clean($_POST['size']);
$message = clean($_POST['message']);

//Input Validations

if($name == '') {
$errflag = true;
}
elseif($email == '') {
$errflag = true;
}
elseif (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){
$errflag = true;
}

$errmsg = 'ERROR: Enter your name and a valid email';

//If there are input validations, redirect back to the registration form

if($errflag) {
$_SESSION['ERR_NAME'] = $name;
$_SESSION['ERR_COMPANY'] = $company;
$_SESSION['ERR_EMAIL'] = $email;
$_SESSION['ERR_PHONE'] = $phone;
$_SESSION['ERR_TYPE'] = $type;
$_SESSION['ERR_SIZE'] = $size;
$_SESSION['ERR_MESSAGE'] = $message;
$_SESSION['ERRMSG'] = $errmsg;
session_write_close();
header("location: index.php");
exit();
}

// If there are not input validations, process email

else {

$send_email = "whatever@mydomain.com";

$email_subject = "SUBJECT";

$email_message = '<html><body>';
$email_message .= "<p>You have received a new contact.</p>";
$email_message .= '<table>';
$email_message .= "<tr><td>Name: </td><td>" . $name . "</td></tr>";
$email_message .= "<tr><td>Company: </td><td>" . $company . "</td></tr>";
$email_message .= "<tr><td>Email: </td><td>" . $email . "</td></tr>";
$email_message .= "<tr><td>Phone: </td><td>" . $phone . "</td></tr>";
$email_message .= "<tr><td>Type: </td><td>" . $type . "</td></tr>";
$email_message .= "<tr><td>Size: </td><td>" . $size . "</td></tr>";
$email_message .= "<tr><td>Message: </td><td>" . $message . "</td></tr>";
$email_message .= "</table>";
$email_message .= "</body></html>";

$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

mail($send_email, $email_subject, $email_message, $headers);
$errmsg = 'Your message has been sent. Thank you!';
$_SESSION['ERRMSG'] = $errmsg;
header("location: index.php");
exit();

} 
Thanks in Advance

Re: PHP mail script and Go Daddy

Posted: Fri Jun 04, 2010 11:10 am
by Jonah Bron
Echo the value of $email. It may have a problem.

Re: PHP mail script and Go Daddy

Posted: Fri Jun 04, 2010 11:51 am
by dtylerroberts
Jonah Bron wrote:Echo the value of $email. It may have a problem.
Thanks for your response. I just tried that and it echoed the email I entered, but still did not send the email. Could it be some kind of security or firewall?

Re: PHP mail script and Go Daddy

Posted: Fri Jun 04, 2010 5:10 pm
by Jonah Bron
You might try putting that line somewhere else, like at the top or bottom. Do you have error reporting on?

Re: PHP mail script and Go Daddy

Posted: Tue Jun 08, 2010 1:26 pm
by dtylerroberts
I tried moving that line around and had the same problem. If I use any other variable, i.e. $company instead of $email, on that line, it works fine. So I guess the issue is:

Code: Select all

" . $email . "
Is that not the correct way to send that variable? It works for the others. I checked my error logs, but I really don't know what to look for there. Any other ideas?

Re: PHP mail script and Go Daddy

Posted: Tue Jun 08, 2010 1:39 pm
by dtylerroberts
It turns out that it was an error on my part when testing it. I used the email test@test.com, which has always worked when I test my scripts, but for some reason does not work here. I tested it with my personal email addresses and it sent. Any explanation why that's the case? Anyway, thanks for the help and I hope I didn't waste too much of your time.