Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

send emails to multiple addresses

Status
Not open for further replies.

waely

Programmer
Joined
Dec 7, 2003
Messages
227
Location
US
hi guys,
can someone help me with this issue. I can sent a php web form to one email but I like to add nother recepient and don't know how. here is my code:
-----------------------------------------
$mailfrom='From: $mailto='myemail@mysite.com';
if($banner==610){
$mailsubject="Registered to Win";
} else {
$mailsubject="Inquiry";
}
......
mail($mailto, $mailsubject, $mailbody, $mailfrom);
-----------------------------------------

thanks for any help.
 
Here's a piece of my code.

$emailHeaders = ("From: ".$recipientString ."\r\nCc: ".$Requester ."\r\n");
mail($toString, $FinalSubject, $FinalEmailBody, $emailHeaders);

As you can see my emailHeaders variable is used to set a from address and a cc to send the email to a second address.

Hope this example helps.
 
thanks. actually I don't know any PHP. I had to use an existed php contact form but I needed to send the email to 2 addresses and here when I ran into a problem. if you have time and if it's not much trouble i can put my codes if you can assist me adding that additional CC to it. in case you can my code is below.
----------------------------------------------------
<?
if((!(isset($fname))) && ($fname=='')){ $errornum++; }
if((!(isset($lname))) && ($lname=='')){ $errornum++; }
if((!(isset($email))) && ($email=='')){ $errornum++; }
if((!(isset($phone))) && ($phone=='')){ $errornum++; }
if($mlist=="Y"){ $cnvml="Yes"; }
else { $cnvml="No"; }
if($errornum == 0){
$mailfrom='From: email@website.com\n';
$mailto='email@website.com';
if($banner==610){
$mailsubject="Registered to Win";
} else {
$mailsubject="Inquiry";
}
$mailbody = "\nFirst Name: $fname\nLast Name: $lname\nCompany: $cname\n";
$mailbody .="Address 1: $addr1\nAddress 2: $addr2\nCity: $city\n";
$mailbody .="State: $state\nZip: $zip\nEmail: $email\nPhone: $phone\n";
$mailbody .="Ring to #: $ringto\n";
$mailbody .="Day: $days\n";
$mailbody .="Time: $calltime\n";
$mailbody .="Fax: $fax\nMailList:";
mail($mailto, $mailsubject, $mailbody, $mailfrom);
?>
--------------------------------------

thank you in advance.
 
I didn't test this, but it looks good.
Just replace extraemail@extraaddress.com with the second email address you want.

<?
if((!(isset($fname))) && ($fname=='')){ $errornum++; }
if((!(isset($lname))) && ($lname=='')){ $errornum++; }
if((!(isset($email))) && ($email=='')){ $errornum++; }
if((!(isset($phone))) && ($phone=='')){ $errornum++; }
if($mlist=="Y"){ $cnvml="Yes"; }
else { $cnvml="No"; }
if($errornum == 0){
$mailfrom='From: email@website.com\r\n';
$mailheaders='$mailfrom Cc: extraemail@extraaddress.com\r\n'
$mailto='email@website.com';
if($banner==610){
$mailsubject="Registered to Win";
} else {
$mailsubject="Inquiry";
}
$mailbody = "\nFirst Name: $fname\nLast Name: $lname\nCompany: $cname\n";
$mailbody .="Address 1: $addr1\nAddress 2: $addr2\nCity: $city\n";
$mailbody .="State: $state\nZip: $zip\nEmail: $email\nPhone: $phone\n";
$mailbody .="Ring to #: $ringto\n";
$mailbody .="Day: $days\n";
$mailbody .="Time: $calltime\n";
$mailbody .="Fax: $fax\nMailList:";
mail($mailto, $mailsubject, $mailbody, $mailheaders);
?>
 
thank you. I tried it and I got the following error:

Parse error: parse error, unexpected T_VARIABLE in /home/virtual/site13/fst/var/ on line 11


line 11 is the mailto line
any idea?
 
never mind. the error was because the missing ; at the end of the previous line.

I tested the script by putting my yahoo and hotmail accounts but never recieve the email. not sure where the problem is..
 
You can stick entirely with your first form, no changes needed but an additional line. That might really make it much easier for you.
Code:
# send first mail
mail($mailto, $mailsubject, $mailbody, $mailfrom);
# second
$mailto = "wherver@another.com";
mail($mailto, $mailsubject, $mailbody, $mailfrom);
That will work for sure, unless you require the mails to be sent out simultaneously.
 
It's easier on the server to use one mail function with a cc then two seperate mail functions.
 
wiser3 said:
It's easier on the server to use one mail function with a cc then two seperate mail functions.

That's not necessarily true.

According to the PHP online manual entry on mail():

The Windows implementation of mail()...Second, the custom headers like From:, Cc:, Bcc: and Date: are not interpreted by the MTA in the first place, but are parsed by PHP...

This seems to me to mean that on Win32, PHP will take an email with multiple CC: headers and automatically compose multiple mail messages, one for each header.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
My recommendation came from the premise that the person asking the question had no PHP knowledge and wanted to achieve this with the least "pain" involved.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top