I'm new to phpmailer and I tried to follow their example. I'm using php mail() function to send emails and I'm getting an error:

"Invalid address: $toYou must provide at least one recipient email address. Mailer Error: You must provide at least one recipient email address."

What email address is valid then? I've tried three and I still get the same error. Thanks

Recommended Answers

All 10 Replies

Member Avatar for LastMitch

@tscina

What email address is valid then? I've tried three and I still get the same error. Thanks

The error means here:

$mail->AddAddress('valid@tscina.com', 'recipient email');

Since you didn't provide the code. I assume got that PHPMailer from Worxware.

Here is a code that will solve that issue

http://phpmailer.worxware.com/index.php?pg=exampleamail

I'm using this code

$mail             = new PHPMailer();

$mail->IsSMTP();
$mail->Host = 'ssl://smtp.gmail.com';
$mail->SMTPAuth      = true;
$mail->SMTPKeepAlive = true;
$mail->Port          = 465;  
$mail->Username      = "my@gmail.com";
$mail->Password      = "password";
$mail->SetFrom('my@email.com', 'First Last');
$to = "my@gmail.com";
$mail->AddAddress('$to',"First Last");
$mail->Subject = "Test Mail";
$message = "messages go here";
$mail->MsgHTML($message);
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
}else{
echo "An e-mail was sent to $to with the subject: $subject";;}

I did put valid mails in the emails. I'm not familiar with smtp settings. I'm still trying to look around

I've changed the ''s to ""s and now i get this message
SMTP Error: Could not connect to SMTP host. Mailer Error: SMTP Error: Could not connect to SMTP host.
BTW this script is offline and I just want to test my script on how it looks like. Thanks for the help btw.

Member Avatar for LastMitch

@tscina

This is wrong:

$mail->Host = 'ssl://smtp.gmail.com';

It just should be this:

$mail->Host = "smtp.gmail.com";

commented: To Rectify what some retard did to LastMitch +0
$mail             = new PHPMailer();

$mail->IsSMTP();
$mail->SMTPDebug = 0;
$mail->SMTPAuth      = true;
$mail->SMTPKeepAlive = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = "smtp.gmail.com";
$mail->Port          = 465; 
$mail->Username      = GUSER;
$mail->Password      = GPWD;
$mail->SetFrom("my@gmail.com", 'First Last');
$mail->Subject = "Test Mail";

$to = "my@yahoo.com";
$mail->AddAddress($to);

This is my new code with the error SMTP Error: Could not connect to SMTP host. Mailer Error: SMTP Error: Could not connect to SMTP host.

Member Avatar for LastMitch

BTW this script is offline and I just want to test my script on how it looks like. Thanks for the help btw.

You have to run this on a host server not offline!

This is my new code with the error SMTP Error: Could not connect to SMTP host. Mailer Error: SMTP Error: Could not connect to SMTP host.

Did you restarted the system then run the script again?

Does host server accept SMTP meaning do let you used this?

Did you enable: ssl?

Read this about gmail:

Did you enable SSL3 for the SMTP4 server?

http://support.google.com/mail/bin/answer.py?hl=en&answer=78775

is there any way i could test run the script without uploading to my host?

turns out i needed to change something with php.ini.

Now I've got a new error

SMTP -> ERROR: Failed to connect to server: Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP? (1743284271) 

Any ideas?

nevermind I got it to work thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.