Sending Multiple Emails

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Gappa
Forum Contributor
Posts: 119
Joined: Fri May 23, 2003 10:02 am

Sending Multiple Emails

Post by Gappa »

Hey all

Just having some troubles with getting some code to send out two emails, at the moment its sending out one just fine and dandy, but the other doesn't appear to be working

Code: Select all

//---------------------------------- 
mail($email, $subject, $receiptMessage,"From:$toAddress"); 
//---------------------------------- 
mail($toAddress,$recipientSubject,$mailContent,"From:$email");
I'm not really to great at this, but maybe the problem is with the above code? If there is no error there then, I guess I'll post the rest of the code.

Be great if someone could help out, thanks all.

Cheers :)
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

<?php
$emails = array('john@doe.com','doe@lalaland.com');

foreach ($emails as $email);
{
     mail($email, $subject, $receiptMessage,"From:$toAddress"); 
}
?>
This is generally the prefered method.

Make sure all your headers are properly sent, including a return email address or your email will get caught in most spam blockers or fail alltogether.
Gappa
Forum Contributor
Posts: 119
Joined: Fri May 23, 2003 10:02 am

Post by Gappa »

Hmm.. not sure how to impliment your solution, this is the code:

Code: Select all

<?php 
/* grabs the POST variables and puts them into variables that we can use */ 
$firstName=$_POST['firstName']; 
$lastName=$_POST['lastName']; 
$company=$_POST['company']; 
$email=$_POST['email']; 
$website=$_POST['website']; 
$countryCode=$_POST['countryCode']; 
$phone=$_POST['phone']; 
$phoneExt=$_POST['phoneExt']; 
$mobile=$_POST['mobile'];  
$address=$_POST['address']; 
$city=$_POST['city']; 
$state=$_POST['state']; 
$country=$_POST['country']; 
$postCode=$_POST['postCode'];  
$inquiring=$_POST['inquiring']; 

//---------VALIDATION----------> 
    if($firstName){//----> CHECK input 
        } 
        else{ 
            $error.="Please, go back and fill out your first name\n";//----> ERROR if no input 
            } 

    if($lastName){//----> CHECK input 
        } 
        else{ 
            $error.="Please, go back and fill out your last name\n";//----> ERROR if no input 
            } 

    if($email){//----> CHECK input 
        } 
        else{ 
            $error.="Please, go back and fill out your e-mail address\n";//----> ERROR if no input 
            } 

    if($phone){//----> CHECK input 
        } 
        else{ 
            $error.="Please, go back and fill out your phone number\n";//----> ERROR if no input 
            } 

    if($address){//----> CHECK input 
        } 
        else{ 
            $error.="Please, go back and fill out your mailing address\n";//----> ERROR if no input 
            } 

    if($city){//----> CHECK input 
        } 
        else{ 
            $error.="Please, go back and fill out your city name\n";//----> ERROR if no input 
            } 

    if($postCode){//----> CHECK input 
        } 
        else{ 
            $error.="Please, go back and fill out your post code\n";//----> ERROR if no input 
            } 
//-------->ERROR FREE?? 
    if($error==""){ 
        echo "Thank you for requesting a catalogue from us! A receipt of your submission will be e-mailed to you almost immediately."; 
//---------------------------------- 
$mailContent="--------CONTACT--------\n" 
            ."First Name: ".$firstName."\n" 
            ."Last Name: ".$lastName."\n" 
            ."Company: ".$company."\n" 
            ."E-mail: ".$email."\n" 
            ."Website: ".$website."\n\n--------PHONE--------\n" 
            ."Phone: ".$countryCode." ".$phone."\n" 
            ."Extension: ".$phoneExt."\n" 
            ."Mobile: ".$mobile."\n\n--------ADDRESS--------\n" 
            ."Street Address: ".$address."\n" 
            ."City: ".$city."\n" 
            ."State: ".$state."\n" 
            ."Country: ".$country."\n" 
            ."Post Code: ".$postCode."\n\n--------INFO--------\n"  
            ."Catalogue Requested: ".$inquiring."\n"; 
//---------------------------------- 
$toAddress="sales@romheldaustralia.com.au";
$subject="Romheld Australia";
$recipientSubject="Romheld Australia"; 
$receiptMessage="Thank you ".$firstName." for requesting a Catalogue from Romheld Australia!\n\n\nHere is what you submitted to us:\n\n" 
            ."--------CONTACT--------\n" 
            ."First Name: ".$firstName."\n" 
            ."Last Name: ".$lastName."\n" 
            ."Company: ".$company."\n" 
            ."E-mail: ".$email."\n" 
            ."Website: ".$website."\n\n--------PHONE--------\n" 
            ."Phone: ".$countryCode." ".$phone."\n" 
            ."Extension: ".$phoneExt."\n" 
            ."Mobile: ".$mobile."\n\n--------ADDRESS--------\n" 
            ."Street Address: ".$address."\n" 
            ."City: ".$city."\n" 
            ."State: ".$state."\n" 
            ."Country: ".$country."\n" 
            ."Post Code: ".$postCode."\n\n--------INFO--------\n" 
            ."Catalogue Requested: ".$inquiring."\n";
//---------------------------------- 
mail($email, $subject, $receiptMessage,"From:$toAddress"); 
//---------------------------------- 
mail($toAddress,$recipientSubject,$mailContent,"From:$email");
       } 
    else{ 

            print "Sorry, but the form cannot be sent until the fields indicated are filled out completely - \n"; 
            print "$error\n"; 
            print "\n"; 
            print "\n"; 
            print "Please use your "Back" button to return to the form to correct the omissions.  Thank you.\n"; 
        } 

?>
Should this really be working?

Thanks for any help :D
Gappa
Forum Contributor
Posts: 119
Joined: Fri May 23, 2003 10:02 am

Post by Gappa »

Hmmm sorry, *bump* :roll:
Post Reply