
Originally Posted by
erepauct
Works great for me.
Which mail function or library are you using?
My PHP mail function using PHPmailer library :-
PHP Code:
<?php
include("phpmailer/class.phpmailer.php");
function filterEmail($email, $chars = ''){
$email = trim(str_replace( array("\r","\n"), '', $email ));
if( is_array($chars) ) $email = str_replace( $chars, '', $email );
$email = preg_replace( '/(cc\s*\:|bcc\s*\:)/i', '', $email );
return $email;
}
function smtpmailer($to, $from, $from_name, $subject, $body) {
$to = filterEmail($to);
$from = filterEmail($from);
global $error;
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->isHTML();
$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';
$mail->Port = 465;
$mail->Username = filterEmail("------@gmail.com");
$mail->Password = "------";
$mail->SetFrom($from, $from_name);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress($to);
if(!$mail->Send()) {
$error = 'Mail error: '.$mail->ErrorInfo;
return false;
} else {
$error = 'Message sent!';
return true;
}
}
?>
I called this function as below :-
PHP Code:
smtpmailer("------@yahoo.com","------@gmail.com","From Name","Welcome","Test");
And when I execute this PHP, I get the following error :-
SMTP Error: Could not connect to SMTP host.
You can check yourself at - http://ingame.x10.mx/social/test.php
My Free hosting account is on Starka Server.
I am sure that my code is correct as it has worked earlier and also it works on my local server. I haven't made any changes to this code since the SMTP Server was down.