Note that there are some explanatory texts on larger screens.

plurals
  1. POAdapt php send mail script to send msg to multiple addresses
    text
    copied!<p>I'd like to adapt the code below so that the e-mail are sent to 2 addresses instead of one. I tried this "sendto = "myaddress1@gmail.com, myaddress2@gmail.com"" without success (msg don't get sent). Any idea? My hosting company is 1&amp;1 (just subscribed so assuming running a recent version of php)</p> <p>Here is the orginal code:</p> <pre><code>&lt;?php $sendto = "myaddress@gmail.com"; $usermail = $_POST['email']; $username = $_POST['name']; $content = nl2br($_POST['msg']); $subject = "New Message from domain.com"; $headers = "From: " . strip_tags($usermail) . "\r\n"; $headers .= "Reply-To: ". strip_tags($usermail) . "\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html;charset=utf-8 \r\n"; $msg = "&lt;html&gt;&lt;body style='font-family:Arial,sans-serif;'&gt;"; $msg .= "&lt;h2 style='font-weight:bold;border-bottom:1px dotted #ccc;'&gt;New message&lt;/h2&gt;\r\n"; $msg .= "&lt;p&gt;&lt;strong&gt;From:&lt;/strong&gt; ".$username."&lt;/p&gt;\r\n"; $msg .= "&lt;p&gt;&lt;strong&gt;E-mail:&lt;/strong&gt; ".$usermail."&lt;/p&gt;\r\n"; $msg .= "&lt;p&gt;&lt;strong&gt;Message:&lt;/strong&gt; ".$content."&lt;/p&gt;\r\n"; $msg .= "&lt;/body&gt;&lt;/html&gt;"; if(@mail($sendto, $subject, $msg, $headers)) { echo "true"; } else { echo "false"; } ?&gt; </code></pre> <p><strong>And the javascript:</strong></p> <pre><code>// Contact form function validateEmail(email) { var reg = /^(([^&lt;&gt;()[\]\\.,;:\s@\"]+(\.[^&lt;&gt;()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; return reg.test(email); } $(document).ready(function() { $(".modalbox").fancybox(); $("#contact").submit(function() { return false; }); $("#send").on("click", function(){ var emailval = $("#email").val(); var msgval = $("#msg").val(); var msglen = msgval.length; var mailvalid = validateEmail(emailval); var nameval = $("#name").val(); if(mailvalid == false) { $("#email").addClass("error"); } else if(mailvalid == true){ $("#email").removeClass("error"); } if(msglen &lt; 4) { $("#msg").addClass("error"); } else if(msglen &gt;= 4){ $("#msg").removeClass("error"); } if(nameval &lt; 2) { //name must be at least 2 characters $("#name").addClass("error"); } else if(nameval &gt;= 2){ $("#name").removeClass("error"); } if(mailvalid == true &amp;&amp; msglen &gt;= 4) { // if both validate we attempt to send the e-mail // first we hide the submit btn so the user doesnt click twice $("#send").replaceWith("&lt;em&gt;sending...&lt;/em&gt;"); $.ajax({ type: 'POST', url: '../sendmessage.php', data: $("#contact").serialize(), success: function(data) { if(data == "true") { $("#contact").fadeOut("fast", function(){ $(this).before("&lt;p&gt;&lt;strong&gt;Success! Your message has been sent, thank you.&lt;/strong&gt;&lt;/p&gt;"); setTimeout("$.fancybox.close()", 1000); }); } } }); } }); }); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload