I am using phpMailer i do not know whats wrong with my code, it return fails after execution? my function which call the phpmailer.php page and takes parameters:
function sendEmail($to,$from,$sender_name="",$subject,$body,$attachement_path){
require("PHPMailer/class.phpmailer.php");
$mail = new PHPMailer();
$host="mail.mysite.com";
$userName="info";
$password="password!";
$mail->IsSMTP(); // set mailer to use SMTP i.e. smtp1.example.com;smtp2.example.com
$mail->Host = $host; // specify main and backup server
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = $userName; // SMTP username i.e email id of an email address
$mail->Password = $password; // SMTP password for the specified email address
$mail->From = $from;
$mail->FromName = $sender_name;
$mail->AddAddress($to); //mail,name
$mail->AddAddress("myBCCMailAddress@gmail.com"); // name is optional
$mail->AddReplyTo($to);//to, name
$mail->WordWrap = 50;
$mail->AddAttachment($attachement_path);
$mail->IsHTML(true); // set email format to HTML
$mail->Subject = $subject;
$mail->Body = $body;
//$mail->AltBody = "This is the body in plain text for non-HTML mail clients";
if(!$mail->Send())
{
return false;
}
else{
return true;
}
}
Here is the calling method of my above function:
if(sendEmail($to,"info@mysite.com","My Company Name",$subject,$body,$path)){
echo 'mail sent';
}
else{
echo('mail failed to send '.$to);
}