|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
Trying to send email to multiple addresses at once.
Hello. I am trying to put together a form that will send email to several people at once. The email addresses, to which a prewritten message will be sent, will be specified by the site visitor. I am using this for a "Refer your friends to this website" type of purpose. The visitor will put in several names and corresponding email addresses (up to about 8 to 10) and I want the mail to all go out at the same time when the visitor hits the "submit" button. The form itself has several fields for inputting friends' addresses. I have assigned a unique variable to each of the "friends" form fields. I just need a way to take these several email variables and note in the PHP script to email to all of them upon clicking the "submit" button once.
Here is a sample form I'm using right now to test things: http://www.dwellingproductions.com/...ferfriends.html You can take a look at this to visualize the potential interface. Below are my attempts at scripting this. So far, I cannot get it to work. I know I've got to be close though. How can I do this? Thanks, in advance, for the help. Jeremy This was my first attempt. This works for one email address, but I cannot figure out how to allow there to be multiple addresses sent at once: <?php $ToEmail = "$emailFriend1"; //The first of several, hopefully $ToName = "$nameFriend1"; //The first of several, hopefully $ToSubject = "Did this work?"; $EmailBody = "The following individual thought you would like to check out our website.nnName: $txtNamenEmail: $txtEmailnURL: $txtURLnComments:n$txtComments"; $EmailFooter = "nnMessage Complete"; $Message = $EmailBody.$EmailFooter; mail($ToEmail, $ToSubject, $Message, "From: $txtEmail"); Print "_root.form.txtStatus=Complete - Your mail has been sent!"; ?> This is my attempt using an array: <?php $to = array(); $to[0] = "emailFriend1"; $to[1] = "emailFriend2"; $ToSubject = "Did this work?"; $EmailBody = "Message from Refer Friends FormnnName: $txtNamenEmail: $txtEmailnURL: $txtURLnComments:n$txtComments"; $EmailFooter = "nnMessage Complete"; $Message = $EmailBody.$EmailFooter; for( $ToEmail = $to) { mail($ToEmail, $ToSubject, $Message, "From: $txtEmail"); } Print "_root.form.txtStatus=Complete - Your mail has been sent!"; ?> |
|
#2
|
|||
|
|||
|
RE: Trying to send email to multiple addresses at once.
OK. After some more attempts at this, here's where I'm at. With the script below, I'm getting a response from the script that the mail has been sent. However, nothing actually gets sent. So, obviously the syntax is legal enough to return the "print" statement. But, for some reason, the script is not executing as desired. Could someone double check the script below to see if there an error in syntax? Otherwise, the method seems to be exactly what is needed in this situation. I can't, for the life of me, figure out why it's not actually sending the emails.
I truly appreciate the assistance. Jeremy <?php // create the arrays (email, name) $email = array(); $name = array(); //find out if the form fields (email, name) have values if(isset($emailFriend1)) { $name[0] = $nameFriend1; $email[0] = $emailFriend1; } if(isset($emailFriend2)) { $name[1] = $nameFriend2; $email[1] = $emailFriend2; } // find out the number in the array $arr_num = count($email); // loop that amount for ($i=0; $i<=$arr_num; $i++) { $to = '"$name[$i]"<$email[$i]>'; $ToSubject = "Did this work?"; $EmailBody = "Message from Refer Friends FormnnName: $txtNamenEmail: $txtEmailnURL: $txtURLnComments:n$txtComments"; $EmailFooter = "nnMessage Complete"; $Message = $EmailBody.$EmailFooter; mail($to, $ToSubject, $Message, "From: $txtEmail"); } Print "_root.form.txtStatus=Complete - Your mail has been sent!"; ?> |
|
#3
|
|||||
|
|||||
|
RE: Trying to send email to multiple addresses at once.
The mail statement can send to multiple people seperated by comma's, therefore all you really need to do is check whether or not the e-mails provided are in fact valid e-mail addresses.. so have people enter their friends e-mails seperated by comma's, and then verify it before submitting.
php Code:
|
|
#4
|
||||
|
||||
|
RE: Trying to send email to multiple addresses at once.
Sometimes php mail() is rejected because the headers are not properly formatted.
B |
|
#5
|
|||
|
|||
|
RE: Trying to send email to multiple addresses at once.
notepad and bakertrg,
Thanks for the replies. I actually want to allow the visitor to use a separate form field to input each of their friends' email addresses. Is there a way I can take advantage of the comma seperated technique without requiring the site visitor to separate the emails by commas? Thanks so much for the assistance. |
|
#6
|
|||
|
|||
|
RE: Trying to send email to multiple addresses at once.
Check out the mail class at www.phpguru.com ...
Works great! |
|
#7
|
|||
|
|||
|
RE: Trying to send email to multiple addresses at once.
hmmm... phpguru.com seems to be down right now. I hope it comes back up.
|
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > Trying to send email to multiple addresses at once. |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|