gavin.sibley Posted March 19, 2012 Share Posted March 19, 2012 hello, just a quick question, as im new to php but think its probably an easy answer. How would i make the code below send an email to the address it pulls from the database (which it already does) and to another address i.e example@example.com $to = "$slide"; thanks, gavin Quote Link to comment Share on other sites More sharing options...
dragon_sa Posted March 19, 2012 Share Posted March 19, 2012 How many email addresses are you wanting to send at once? If it is just to one extra email address just call the mail function twice specifying a different to variable for the second email, If its many addresses you need to put it in a loop, but you also need to be careful not to send to many emails at once or you can get yourself blacklisted or blocked by your host for spam, the way around that is to incorporate a pause between blocks of say 10 at a time for example emails. Quote Link to comment Share on other sites More sharing options...
gavin.sibley Posted March 19, 2012 Author Share Posted March 19, 2012 I only want to send the email to the address pulled from the database (which will only be one at a time) and i want a copy sent to myself. in this case would i do it like this? $to = "$slide"; $to = "example@example.com"; thanks Quote Link to comment Share on other sites More sharing options...
SaCH Posted March 19, 2012 Share Posted March 19, 2012 Try something like this <?php //this is the email id which you pull form your database. $to = $slide[email]; //this is the another email that you want to send the email. $another = "example@example.com"; //sending the email with php mail() function //1st sending the mail to the email id which you pull from database. if(mail($to,$subject,$message,$headers)) { //2nd sending the mail to the email id which you given as $another variable if the 1st mail is success. mail($another,$subject,$message,$headers); } else { echo 'Email not sent to'; } ?> [/code] Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted March 19, 2012 Share Posted March 19, 2012 How many email addresses are you wanting to send at once? If it is just to one extra email address just call the mail function twice specifying a different to variable for the second email, If its many addresses you need to put it in a loop, but you also need to be careful not to send to many emails at once or you can get yourself blacklisted or blocked by your host for spam, the way around that is to incorporate a pause between blocks of say 10 at a time for example emails. No, don't loop the mail function to send the same message to multiple recipients. Either add a cc or bcc header to the mail that you are sending. Or just add multiple addresses in the to header seporated with either commas or semi-colons depending on the mail servers setup. Quote Link to comment Share on other sites More sharing options...
gavin.sibley Posted March 19, 2012 Author Share Posted March 19, 2012 so like this? $to = "$slide; example@example.com"; Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted March 19, 2012 Share Posted March 19, 2012 just about, because you are addressing an array value use {} around it: $to = "{$slide[email]}; example@example.com"; Quote Link to comment Share on other sites More sharing options...
dragon_sa Posted March 19, 2012 Share Posted March 19, 2012 The idea of the loop is really for a newsletter function of a site, not for a couple of emails, I had no idea which he was trying to achieve as he said he was pulling emails from a database, so I mentioned both options Quote Link to comment Share on other sites More sharing options...
gavin.sibley Posted March 19, 2012 Author Share Posted March 19, 2012 thanks both got it working now, using the semi colon in the To field. thanks Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted March 19, 2012 Share Posted March 19, 2012 The idea of the loop is really for a newsletter function of a site, not for a couple of emails, I had no idea which he was trying to achieve as he said he was pulling emails from a database, so I mentioned both options newsletters should either be fed using rss/atom/etc to client subscriptions (most every mail client supports RSS feeds) or if going as a mail item, bundled in the bcc using the multiple address method with a single message to a dummy address in the to header. This reduces server load and network bandwidth. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.