add multiple recipients to contact form |
add multiple recipients to contact form |
justine |
Jan 14 2014, 01:32 PM
Post
#1
|
Member Group: Members Posts: 54 Joined: 4-February 09 Member No.: 7,724 |
Hi, Can you please advise on how I would add multiple recipients to this php contact form? I've tried many suggestions I've found online, but none of them work. Thanks so much!
The page link is: http://pscwichita.com/site/contactus.html. Here is the code: <?php $your_name = "Plastic Surgery Center"; $your_email = "***@***.net"; $your_web_site_name = "Plastic Surgery Center"; ?> <?php //If the form is submitted if(isset($_POST['name'])) { //variables $errorMessage = ""; //Check to make sure that the name field is not empty if(trim($_POST['name']) === '') { $hasError = true; } else { $name = trim($_POST['name']); } //Check to make sure sure that a valid email address is submitted if(trim($_POST['email']) === '') { $hasError = true; } else if (!preg_match('^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$^', trim($_POST['email']))) { $hasError = true; $errorMessage = "Please enter a valid email address!"; } else { $email = trim($_POST['email']); } //phone if(isset($_POST['phone'])) $phone = trim($_POST['phone']); //company name if(isset($_POST['company_name'])) $company_name = trim($_POST['company_name']); //company url if(isset($_POST['company_url'])) $company_url = trim($_POST['company_url']); //Check to make sure comments were entered if(trim($_POST['message']) === '') { $hasError = true; } else { if(function_exists('stripslashes')) { $comments = stripslashes(trim($_POST['message'])); } else { $comments = trim($_POST['message']); } } //If there is no error, send the email if(!isset($hasError)) { $emailTo = $your_email; $subject = 'Contact Form Submission from '.$name; //message body $body ="Name: $name \n\n"; $body .="Email: $email \n\n"; if(isset($phone)) $body .="Phone:$phone\n\n"; if(isset($company_name)) $body .="Company Name:$company_name\n\n"; if(isset($company_url)) $body .="Company Url:$company_url \n\n"; $body .="Message: $comments"; $headers = 'From: '.$your_web_site_name.' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email; mail($emailTo, $subject, $body, $headers); $emailSent = true; } } ?> <?php if(isset($emailSent) == true) { ?> <div class="ok_box"> <h3>Thanks, <?php echo $name;?></h3> <p>Your email was successfully sent. We will be in touch soon.</p> </div> <?php } ?> <?php if(isset($hasError) ) { ?> <div class="error_box"> There was an error submitting the form. <br /> <?php echo $errorMessage;?> </div> <?php } ?> This post has been edited by Christian J: Jan 14 2014, 10:37 PM |
CharlesEF |
Jan 14 2014, 02:56 PM
Post
#2
|
Programming Fanatic Group: Members Posts: 1,981 Joined: 27-April 13 From: Edinburg, Texas Member No.: 19,088 |
You can add multiple emails if you place a , between each email. So, this line would become $your_email = "foo@***.net,bar@***.com" etc...
This post has been edited by Christian J: Jan 14 2014, 10:38 PM |
justine |
Jan 14 2014, 05:29 PM
Post
#3
|
Member Group: Members Posts: 54 Joined: 4-February 09 Member No.: 7,724 |
Hi Charles,
Thank you, but I did that and it didn't work. Any other ideas? Thanks! |
CharlesEF |
Jan 14 2014, 06:48 PM
Post
#4
|
Programming Fanatic Group: Members Posts: 1,981 Joined: 27-April 13 From: Edinburg, Texas Member No.: 19,088 |
Hi Charles, Thank you, but I did that and it didn't work. Any other ideas? Thanks! Strange, I use that same format and it works for me. $your_email is assigned to $emailTo and that variable is used in the mail command. To be honest I use a little different format but I did test my suggestion before I posted and it did work. The format I use is: $emailTo = '"Joe Blow" <jblow@blow.com>,"Joe Blow" <jblow@blow.net>'; and it works for me. |
justine |
Jan 14 2014, 10:18 PM
Post
#5
|
Member Group: Members Posts: 54 Joined: 4-February 09 Member No.: 7,724 |
Arghh! I can't seem to get it to work. This is what I have now, and it isn't going to either email address.
$your_name = "Plastic Surgery Center"; $your_email = "foo@***.net, bar@***.net"; $your_web_site_name = "Plastic Surgery Center"; Sorry to be a pain! Thx!! This post has been edited by Christian J: Jan 14 2014, 10:39 PM |
CharlesEF |
Jan 14 2014, 10:25 PM
Post
#6
|
Programming Fanatic Group: Members Posts: 1,981 Joined: 27-April 13 From: Edinburg, Texas Member No.: 19,088 |
Arghh! I can't seem to get it to work. This is what I have now, and it isn't going to either email address. $your_name = "Plastic Surgery Center"; $your_email = "foo@***.net, bar@***.net"; $your_web_site_name = "Plastic Surgery Center"; Sorry to be a pain! Thx!! Well, the only thing I see is the space after the comma. The PHP manual examples and my example do not have a space. The only thing between the 2 email addresses should be a comma. Try this: $your_email = "foo@***.net,bar@***.net"; 1 thing, I would mangle your email address before you post them in a forum. Bots can harvest them. This post has been edited by Christian J: Jan 14 2014, 10:39 PM |
Christian J |
Jan 14 2014, 10:41 PM
Post
#7
|
. Group: WDG Moderators Posts: 9,656 Joined: 10-August 06 Member No.: 7 |
I edited the emails in the above posts (hopefully without changing the syntax).
|
justine |
Jan 14 2014, 10:48 PM
Post
#8
|
Member Group: Members Posts: 54 Joined: 4-February 09 Member No.: 7,724 |
Arghh! I can't seem to get it to work. This is what I have now, and it isn't going to either email address. $your_name = "Plastic Surgery Center"; $your_email = "foo@***.net, bar@***.net"; $your_web_site_name = "Plastic Surgery Center"; Sorry to be a pain! Thx!! Well, the only thing I see is the space after the comma. The PHP manual examples and my example do not have a space. The only thing between the 2 email addresses should be a comma. Try this: $your_email = "foo@***.net,bar@***.net"; 1 thing, I would mangle your email address before you post them in a forum. Bots can harvest them. Thx! It still isn't working. Is there something else I should change in the form? Thx again! |
CharlesEF |
Jan 14 2014, 10:50 PM
Post
#9
|
Programming Fanatic Group: Members Posts: 1,981 Joined: 27-April 13 From: Edinburg, Texas Member No.: 19,088 |
Looks good to me, thanks.
|
CharlesEF |
Jan 14 2014, 10:52 PM
Post
#10
|
Programming Fanatic Group: Members Posts: 1,981 Joined: 27-April 13 From: Edinburg, Texas Member No.: 19,088 |
|
justine |
Jan 14 2014, 11:06 PM
Post
#11
|
Member Group: Members Posts: 54 Joined: 4-February 09 Member No.: 7,724 |
Thx! It still isn't working. Is there something else I should change in the form? Thx again! Can you attach the entire HTML and PHP page into a post here? Here's the contact page. My Webpage Here's the contact php page. http://pscwichita.com/site/contact_form.php Let me know if you want me to paste code, too. Thx! |
CharlesEF |
Jan 14 2014, 11:40 PM
Post
#12
|
Programming Fanatic Group: Members Posts: 1,981 Joined: 27-April 13 From: Edinburg, Texas Member No.: 19,088 |
Thx! It still isn't working. Is there something else I should change in the form? Thx again! Can you attach the entire HTML and PHP page into a post here? Here's the contact page. My Webpage Here's the contact php page. http://pscwichita.com/site/contact_form.php Let me know if you want me to paste code, too. Thx! I can't see the PHP code when you post a link. PHP is server side code and is not passed down to the browser. I need you to actually attach the contact page to a post here. It is a 2 step process. When you click the " Reply button you should see 4 sections. Section 1 is where you write the message. Section 2 is the Post Options and Section 3 is the File Attachments section. Browse to your file and select it, then click the 'Add This Attachment' button. After the file is uploaded the section will change and offer an option 'Add to post' (something like that). Click this to actually add the attachment to your post. |
justine |
Jan 14 2014, 11:44 PM
Post
#13
|
Member Group: Members Posts: 54 Joined: 4-February 09 Member No.: 7,724 |
Thx! It still isn't working. Is there something else I should change in the form? Thx again! Can you attach the entire HTML and PHP page into a post here? Here's the contact page. My Webpage Here's the contact php page. http://pscwichita.com/site/contact_form.php Let me know if you want me to paste code, too. Thx! I can't see the PHP code when you post a link. PHP is server side code and is not passed down to the browser. I need you to actually attach the contact page to a post here. It is a 2 step process. When you click the " Reply button you should see 4 sections. Section 1 is where you write the message. Section 2 is the Post Options and Section 3 is the File Attachments section. Browse to your file and select it, then click the 'Add This Attachment' button. After the file is uploaded the section will change and offer an option 'Add to post' (something like that). Click this to actually add the attachment to your post. Sorry! I didn't scroll far enough. contact_form.php ( 2.4k ) Number of downloads: 465 contactus.html ( 32.86k ) Number of downloads: 521 |
CharlesEF |
Jan 15 2014, 12:18 AM
Post
#14
|
Programming Fanatic Group: Members Posts: 1,981 Joined: 27-April 13 From: Edinburg, Texas Member No.: 19,088 |
I put your files in a temp directory on my website and sent a test message. I got 2 emails. All I did was replace your 2 email addresses with my 2 email addresses, that's it.
Click here to test for yourself. The page layout will look bad because I don't have your CSS files but scroll down far enough and you will see the contact form. This post has been edited by CharlesEF: Jan 15 2014, 12:21 AM |
justine |
Jan 15 2014, 08:55 AM
Post
#15
|
Member Group: Members Posts: 54 Joined: 4-February 09 Member No.: 7,724 |
I put your files in a temp directory on my website and sent a test message. I got 2 emails. All I did was replace your 2 email addresses with my 2 email addresses, that's it. Click here to test for yourself. The page layout will look bad because I don't have your CSS files but scroll down far enough and you will see the contact form. Hi Charles, I did get two emails from you last night! Thanks for all your help. But, I just tested it again myself, and I didn't get any. Very odd! |
CharlesEF |
Jan 15 2014, 02:44 PM
Post
#16
|
Programming Fanatic Group: Members Posts: 1,981 Joined: 27-April 13 From: Edinburg, Texas Member No.: 19,088 |
I put your files in a temp directory on my website and sent a test message. I got 2 emails. All I did was replace your 2 email addresses with my 2 email addresses, that's it. Click here to test for yourself. The page layout will look bad because I don't have your CSS files but scroll down far enough and you will see the contact form. Hi Charles, I did get two emails from you last night! Thanks for all your help. But, I just tested it again myself, and I didn't get any. Very odd! I just sent you another test email, did you get 2 messages? The test I just did now is your original contactus.html and contact_form.php files. I changed nothing. If you do get today's test message then I'm at a loss as to why it works for me but not for you. |
justine |
Jan 15 2014, 05:29 PM
Post
#17
|
Member Group: Members Posts: 54 Joined: 4-February 09 Member No.: 7,724 |
That is so very strange. Yes, I did get yours this afternoon. Thanks again!
|
CharlesEF |
Jan 15 2014, 06:11 PM
Post
#18
|
Programming Fanatic Group: Members Posts: 1,981 Joined: 27-April 13 From: Edinburg, Texas Member No.: 19,088 |
That is so very strange. Yes, I did get yours this afternoon. Thanks again! In that case I'm out of ideas. I changed nothing and it works for me. Maybe you should contact your web host provider and see if there might be some kind of problem with your PHP setup. At least find out what version of PHP they are using. Maybe they need to update PHP? This post has been edited by CharlesEF: Jan 15 2014, 06:12 PM |
justine |
Jan 16 2014, 12:16 PM
Post
#19
|
Member Group: Members Posts: 54 Joined: 4-February 09 Member No.: 7,724 |
That is so very strange. Yes, I did get yours this afternoon. Thanks again! In that case I'm out of ideas. I changed nothing and it works for me. Maybe you should contact your web host provider and see if there might be some kind of problem with your PHP setup. At least find out what version of PHP they are using. Maybe they need to update PHP? Okay. I contacted the server, and below is what they told me. I am at a loss, though as to how to fix it. Any chance you could please advise? Thanks!! The problem appears to be here in contact_form.php: $your_email = "xx@cox.net,info@bb.com"; I would expect this to throw an error when multiple recipients are desired based off of how the script appears to be formatting the message. The code that calls the variable doesn’t appear to have any logic for parsing multiple recipients. From the file code: //If there is no error, send the email if(!isset($hasError)) { $emailTo = $your_email; // there is nothing to verify that this is correctly formatted, causing your issue. $subject = 'Contact Form Submission from '.$name; //message body $body ="Name: $name \n\n"; $body .="Email: $email \n\n"; if(isset($phone)) $body .="Phone:$phone\n\n"; if(isset($company_name)) $body .="Company Name:$company_name\n\n"; if(isset($company_url)) $body .="Company Url:$company_url \n\n"; $body .="Message: $comments"; $headers = 'From: '.$your_web_site_name.' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email; mail($emailTo, $subject, $body, $headers); When the variable value is expanded from $emailTo, the lack of a properly formatted SINGLE email address causes the error. This is not a php/server configuration issue. |
CharlesEF |
Jan 16 2014, 01:54 PM
Post
#20
|
Programming Fanatic Group: Members Posts: 1,981 Joined: 27-April 13 From: Edinburg, Texas Member No.: 19,088 |
That is so very strange. Yes, I did get yours this afternoon. Thanks again! In that case I'm out of ideas. I changed nothing and it works for me. Maybe you should contact your web host provider and see if there might be some kind of problem with your PHP setup. At least find out what version of PHP they are using. Maybe they need to update PHP? Okay. I contacted the server, and below is what they told me. I am at a loss, though as to how to fix it. Any chance you could please advise? Thanks!! The problem appears to be here in contact_form.php: $your_email = "xx@cox.net,info@bb.com"; I would expect this to throw an error when multiple recipients are desired based off of how the script appears to be formatting the message. The code that calls the variable doesn’t appear to have any logic for parsing multiple recipients. From the file code: //If there is no error, send the email if(!isset($hasError)) { $emailTo = $your_email; // there is nothing to verify that this is correctly formatted, causing your issue. $subject = 'Contact Form Submission from '.$name; //message body $body ="Name: $name \n\n"; $body .="Email: $email \n\n"; if(isset($phone)) $body .="Phone:$phone\n\n"; if(isset($company_name)) $body .="Company Name:$company_name\n\n"; if(isset($company_url)) $body .="Company Url:$company_url \n\n"; $body .="Message: $comments"; $headers = 'From: '.$your_web_site_name.' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email; mail($emailTo, $subject, $body, $headers); When the variable value is expanded from $emailTo, the lack of a properly formatted SINGLE email address causes the error. This is not a php/server configuration issue. As far as I understand the mail command there is no parsing to do in the php script. The mail command itself does the parsing. You just need to be sure the email addresses are formatted correctly (and are valid - of cource). I placed your contactus and php script on my website, it works fine as is. For this reason I think your support person got it wrong. Point them to the mail manual found here. Did you tell them that someone else can run your php script and do get 2 emails? This post has been edited by CharlesEF: Jan 16 2014, 01:56 PM |
Lo-Fi Version | Time is now: 26th April 2024 - 01:06 AM |