How to use PHPmailer? Help me with its API
I have created a PHP page, whereby having the page to send automatically to user, i tried using PHPMailer but it only says "SMTP ERROR: cannot access host or somthing like that "
here's my code:
PHPMailer 开发者_如何转开发x = new PHPMailer();
x->isSMTP();
x->Host = myhost;
x->Port = myport;
x->AddAddress(recipientAddress);
x->From = myEmail;
x->Username = username;
x->Password = password;
x.Send();
here is quick fix of your code
$mail = new PHPMailer();
$mail->IsMail();
$mail->setCharset = "UTF-8";
$mail->Host = "localhost";
// $mail->Port = "587"; you don't need it now
$mail->AddAddress("recipientAddress");
$mail->setFrom = "myEmail";
$mail->Subject = "Subject";
$mail->Username = "username";
$mail->Password = "password";
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->Send();
so now you would get more debug messages and track your errors and fix them :)
update : okay that is easy :
The function $mail->IsMail(); indicates that the letter must be sent using mail() function. Other methods are:
IsSendmail - via sendmail command.
IsQmail - directly via qMail MTA.
IsSMTP - via SMTP server.
Try removing the isSMTP
line so it will use the mail settings configured in PHP.
This looks that your SMTP settings on the www server are wrong.
Check if you can send the e-mail with the SMTP configuration you specified - if not:
- is there a SMTP server running on
myhost
:myport
? - Does it listen on the interface you're using to talk to it?
- Is it configured to accept mail from your host?
- Is it configured to accept mail for the recipients?
精彩评论