I once had this problem on my development machine. Rather then trying to configure SMTP correctly, I asked another server to do the job for me. You can use cURL library to post the required fields ($from, $to, $body etc), and the corresponding script on the remote machine will do the email for you.
local machine code:
<?php
function curl_post($url, array $post = array(), array $options = array()) {
$defaults = array(
CURLOPT_POST => 1,
CURLOPT_HEADER => 0,
CURLOPT_URL => $url,
CURLOPT_FRESH_CONNECT => 1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_FORBID_REUSE => 1,
CURLOPT_TIMEOUT => 20,
CURLOPT_POSTFIELDS => $post
);
$ch = curl_init();
curl_setopt_array($ch, ($options + $defaults));
if( ! $result = curl_exec($ch)) {
throw new ErrorException ("curl_post error: " . stripslashes(curl_error($ch)));
}
curl_close($ch);
return $result;
}
function email($from, $to, $subject, $body) {
$result = curl_post ("http://server-with-email/my-email-controller.php", array ("to"=>$to, "from"=>$from, "subject"=>$subject, "body"=>$body));
}
// usage:
$result = email ("from@email.com", "to@email.com", "an email for you", "content of mail");
remote machine code: (my-email-controller.php)
<?php
$to = $_POST["to"];
$from = $_POST["from"];
$subject = $_POST["subject"];
$body = $_POST["body"];
$headers =
"Content-Type: text/plain; charset=UTF-8" . "\r\n" .
"MIME-Version: 1.0" . "\r\n" .
"From: $from" . "\r\n" .
"X-Mailer: PHP/" . phpversion();
if (mail ($to, $subject, $body , $headers)===TRUE) {
echo "mail was sent ok";
} else {
echo "mail failed"
}