| Forum Home | ||||
| Press F1 | ||||
| Thread ID: 96687 | 2009-01-19 07:00:00 | PHP question | johcar (6283) | Press F1 |
| Post ID | Timestamp | Content | User | ||
| 740234 | 2009-01-19 07:00:00 | I'm reusing this code for a form on a website I'm using. As it stands, this code sends a Plain Text email to the specified recipient ($receiver="EMAILADDRESS@DOMAIN"). What I would like to do, is additionally send a copy of the form/data submitted, to the user who submitted it (sender email address is/will be a mandatory field on the form - which is/will be an HTML form). Even better, I'd like to send the email (to both parties) in HTML format with the layout similar to the form if possible. But this requirement is less important than the copy to sender email.... Any PHP experts out there with some suggestions? <? $receiver="EMAILADDRESS@DOMAIN"; $subject="Website Contact"; $header="MIME-Version: 1.0\r\nContent-type: text/plain; charset=iso-8859-1\r\n"; //'add every form element and its value to the email $body=""; foreach (array_keys($_POST) as $el) { if (strcmp("subject",strtolower($el))==0) $subject=$subject." -- ".$_POST[$el]; $value=$_POST[$el]; $display=""; if (is_array($value)) { foreach ($value as $everydisplay) { $display.=$everydisplay." "; } } else { $display=$value; } $body=$body. $el . ": " . $display . "\r\n"; } //mail($receiver,$subject,$body); if ($body!="") mail($receiver,$subject,$body,$header); ?> |
johcar (6283) | ||
| 740235 | 2009-01-19 07:26:00 | I'll watch this thread with great interest :D Here's the code Ive used on one or two sites: <?php // Receiving variables @$ip= $_SERVER['REMOTE_ADDR']; @$jobtype = addslashes($_POST['jobtype']); @$mobile = addslashes($_POST['mobile']); @$name = addslashes($_POST['name']); @$phone = addslashes($_POST['phone']); @$email = addslashes($_POST['email']); @$location = addslashes($_POST['location']); @$generalnotes = addslashes($_POST['generalnotes']); //Sending Email to owner $header = "From: $email\n" . "Reply-To: $email\n" ; $subject = "New 0800tulips website enquiry"; $email_to = "$location@domain . co . nz"; $message = "Visitor's IP: $pfw_ip\n\n" . "Job Type: $jobtype\n\n" . "Email Address: $email\n" . "Contact Name: $name\n" . "Phone Number: $phone\n" . "Mobile Number: $mobile\n" . "General Notes: $generalnotes\n\n" . "End of Email"; @mail($email_to, $subject ,$message ,$header ) ; include 'submit_success . php'; ?> Reading here it says you cant "CC" somebody: . php . net/function . mail" target="_blank">nz2 . php . net But I wonder if you can just compose the email twice? Once to each recipient? Ive never really tried . . . 1 |
Chilling_Silence (9) | ||
| 740236 | 2009-01-19 07:43:00 | could you not add 2 receivers? googled: link css to php lots of helpful links, i assume youd use a css? |
hueybot3000 (3646) | ||
| 740237 | 2009-01-19 07:43:00 | Could you just call the "mail" function again? assume you captured the new sender's email in variable $senderEmail if ($body!="") { mail($receiver,$subject,$body,$header); mail($senderEmail,$subject,$body,$header); } As for sending the email in HTML format, you would need to change your response to spit out multi-part content, with say the first part being "text/plain" (for email clients that can't handle html) and the second part being "text/html". Sorry, don't know php specifically to give you sample code, but that's the general technique. |
dyewitness (9398) | ||
| 740238 | 2009-01-19 07:57:00 | could you not add 2 receivers? googled: link css to php lots of helpful links, i assume youd use a css? The problem is that one receiver will be static, the second (the form submitter) is a variable... Could you just call the "mail" function again? assume you captured the new sender's email in variable $senderEmail if ($body!="") { mail($receiver,$subject,$body,$header); mail($senderEmail,$subject,$body,$header); } As for sending the email in HTML format, you would need to change your response to spit out multi-part content, with say the first part being "text/plain" (for email clients that can't handle html) and the second part being "text/html". Sorry, don't know php specifically to give you sample code, but that's the general technique. Cool - thanks! Will try the "senderEmail" call later tonight. Looks like it could be just what I need. |
johcar (6283) | ||
| 1 | |||||