Link to home
Start Free TrialLog in
Avatar of Pedro Chagas
Pedro ChagasFlag for Portugal

asked on

Send more then one e-mail in phpmailer

Hi E's, I use phpmailer 5.0.2 for send e-mails. I use my gmail account (gmail smtp).
I use the basic code that comes with phpmailer script, and you can see them in snippet code. That script work very well, but just send for one box.
If I want send for more boxs, what I have to change in the code?
I think I have to change something in this lines:
$address = "whoto@otherdomain.com";
$mail->AddAddress($address, "John Doe");

Is possible send the same e-mail to various box's, and how?

Regards, JC
<?php
 
//error_reporting(E_ALL);
error_reporting(E_STRICT);
 
date_default_timezone_set('America/Toronto');
 
require_once('../class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
 
$mail             = new PHPMailer();
 
$body             = file_get_contents('contents.html');
$body             = eregi_replace("[\]",'',$body);
 
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host       = "mail.yourdomain.com"; // SMTP server
$mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
                                           // 1 = errors and messages
                                           // 2 = messages only
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
$mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
$mail->Port       = 465;                   // set the SMTP port for the GMAIL server
$mail->Username   = "yourusername@gmail.com";  // GMAIL username
$mail->Password   = "yourpassword";            // GMAIL password
 
$mail->SetFrom('name@yourdomain.com', 'First Last');
 
$mail->AddReplyTo("name@yourdomain.com","First Last");
 
$mail->Subject    = "PHPMailer Test Subject via smtp (Gmail), basic";
 
$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
 
$mail->MsgHTML($body);
 
$address = "whoto@otherdomain.com";
$mail->AddAddress($address, "John Doe");
 
$mail->AddAttachment("images/phpmailer.gif");      // attachment
$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
 
if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Message sent!";
}

Open in new window

SOLUTION
Avatar of termlimit
termlimit
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Pedro Chagas

ASKER

Great 3 solutions.
I just have a doubt, client see the e-mail I use for send the e-mails, and I want put "noreply@mydomain.com", like you can see in attach image.
What I have to change?

Regards, JC
mail1.jpg
change:

$mail->SetFrom('name@yourdomain.com', 'First Last');


to:

$mail->SetFrom('noreply@mydomain.com');

and get rid of:
$mail->AddReplyTo("name@yourdomain.com","First Last");
I don't know if google/gmail will accept it, but try to change the From header, like this:

$mail->SetFrom('noreply@mydomain.com', 'DomainOrCompanyName');
I use:
$mail->SetFrom('noreply@mydomain.com', 'Test');
and appear the same thing!

Do you have any idea if it is possible?
Is better I open a new question for this issue?
Do you thing if I change phpmailer version I resolve the issue?

Regards, JC
Did you remove $mail->AddReplyTo() ?

>> Do you have any idea if it is possible?

It is possible, but I don't know if it is possible with Gmail.

>> Is better I open a new question for this issue?

It is a different question, so you should open a new question, yes... :)

Doing so might attract the attention of more experts.

>> Do you thing if I change phpmailer version I resolve the issue?

I don't think the version of phpmailer is relevant.
I was in the middle of writing a response when I saw cxr's answer come across so I will remove all that he stated above.  I don't believe it is since most of the major carriers (Yahoo, MSN, etc) use an MUA that is not controlled by the user but rather their own system of authenticated user.  This translates to the fact that the user can't send spam from their account (which is what you are trying to do sort of, although this is not your intention it is seen like that through the mail system).
Hold on @termlimit, I'm not a spammer, very far of this.....
I search a new solution for my project "allfreephoto.com". The project consist in customer made a download of pictures, but this download is made by email (customer choose the picture and custumer receive that picture in e-mail).
In my recent tests I discovery some of that e-mails go to the junk box of customers mail recipients, and others don't enter in her recipients. So, I think in phpmailer with gmail smtp! (In all of time I use the smtp of allfreephoto)
(All versions of allfreephoto send about 100 - 120 pictures everyday by e-mail)

Because I don't want customer reply emails (have a place in the site for customer contact us), I have the idea of put the e-mail sender "noreply@allfreephoto.com".
Is just this.....

Regards, JC
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I'm sorry too, thanks for all!!!