This is how I fixed it: Install phpmailer.
Here is a tutorial how to send mail with PHP mailer
Here is my code:
<?php
require 'PHPMailer-master/class.phpmailer.php';
function sendmail($to,$subject, $body)
{
return sendmailfrom($to,"myemail@gmail.com","from me", $subject, $body);
}
function sendmailfrom($to, $from, $from_name, $subject, $body)
{
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 0; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = 'smtp.gmail.com';//required for gmail
$mail->Port = 465;
$mail->Username = 'myemail@gmail.com';//the email I want to send from
$mail->Password = 'mypassword'; //my password
$mail->SetFrom($from, $from_name);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress($to);
if(!$mail->Send()) return false;
else return true;
}
?>
When ever I want to send mail I include this code, via include("filename.php")
, and run sendmail($to,$subject, $body);