Here's the code
PHP Code:
include("class.phpmailer.php");
include("class.smtp.php");
function makeLink($string){
// make sure there is an http:// on all URLs
$string = preg_replace("/([^\w\/])(www\.[a-z0-9\-]+\.[a-z0-9\-]+)/i", "$1http://$2",$string);
//make all URLs links
$string = preg_replace("/([\w]+:\/\/[\w-?&;#~=\.\/\@]+[\w\/])/i","<a target=\"_blank\" href=\"$1\">$1</A>",$string);
// make all emails hot links
$string = preg_replace("/([\w-?&;#~=\.\/]+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?))/i","<A HREF=\"mailto:$1\">$1</A>",$string);
return $string;
}
function googleMail($email_to,$email_from,$email_subject, $email_message){
//$temp = split('@',$email_to);
$temp = explode('@',$email_to);
$toName = $temp[0];
//$temp = split('@',$email_from);
$temp = explode('@',$email_from);
$fromName = $temp[0];
$email_message_html = $email_message;
$email_message_html = preg_replace("/[\n\r]/","<br>",$email_message_html);
//$email_message_html = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]","<a href=\"\\0\">\\0</a>", $email_message_html);
$email_message_html = makeLink($email_message_html);
$mail = new PHPMailer();
//$body = $mail->getFile('contents.html');
//$body = eregi_replace("[\]",'',$body);
$mail->IsSMTP();
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port
$mail->Username = "XXXXXXX@gmail.com"; // GMAIL username
$mail->Password = "XXXXXXXX"; // GMAIL password
$mail->From = $email_from;
$mail->FromName = $fromName;
$mail->Subject = $email_subject;
$mail->AltBody = $email_message; //Text Body
$mail->WordWrap = 50; // set word wrap
$mail->MsgHTML($email_message_html);
$mail->AddReplyTo($email_from,$fromName);
//$mail->AddAttachment("/path/to/file.zip"); // attachment
//$mail->AddAttachment("/path/to/image.jpg", "new.jpg"); // attachment
$mail->AddAddress($email_to,$toName);
$mail->IsHTML(true); // send as HTML
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
exit();
} else {
echo "Message has been sent";
}
}
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
//--------------------------------------------------------------------
$first_name="test cowboy";
$email_from="NoReply@gmail.com";
$email_to="XXXXXXXXX@gmail.com";
$email_subject="A SACRIFICE TO THE EMAIL GODS";
$email_message = "Form details below.\n\n";
$email_message .= "First Name: ".clean_string($first_name)."\n";
//$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
//$email_message .= "Telephone: ".clean_string($telephone)."\n";
//$email_message .= "Comments: ".clean_string($comments)."\n";
// create email headers for the PHP mail test
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
//mail($email_to, $email_subject, $email_message, $headers); // normal PHP mail which seems to drop mails
googleMail($email_to,$email_from,$email_subject, $email_message);
exit();
And here is the link to the site...Perhaps you have better detective skills...
Remember... if you swap it to the normal PHP function... then you do not get the server 500 error... it seems to work... BUT the email never comes!
If you try the script above... remember to put your GMAIL accounts in...
I think its either the socket calls, or the secure socket calls that are doing it...
On the test server... it works... so I'm struggling to fix what is not broken here...
To make this work on our server we had to load the socket extensions in PHP... but then this is windows so it could be s little different...
I still think its some kind of firewall thing... GMAIL is on a weird smtp channel... not the standard 25 or whatever...
Thanks... I'm snookered ...