maextra7 Posted January 9, 2007 Share Posted January 9, 2007 Hey AllCan anyone help me with some code to collect an email address put in by a user on a form, and then when they click submit is auto emails then the info they have requested pulling their email address through from the form?I am hoping that there could be a field so if people want mor einfo they can put in their email address and click a button to send them the info.I am a total beginner so please be gentle! Any help would be greatly appreciated!Thanks Link to comment https://forums.phpfreaks.com/topic/33439-collect-an-email-address-then-mail-it/ Share on other sites More sharing options...
ted_chou12 Posted January 9, 2007 Share Posted January 9, 2007 [code]<?php //php email functionif(isset($_POST['submit'])){$email = $_POST['email'];$subject = "More Info";$from = "[email protected]";// I dont find this perticularly useful, they dont work...$return = "[email protected]";// This one as well. so dont bother.$body = "This is where your info goes";$headers = "MIME-Version: 1.0rn";$headers .= "Content-type: text/html; charset=iso-8859-1rn";$headers .= "From: myname<$from>rn"; $headers .= "Return-Path: <$return>";if (mail($email, $subject, $body, $headers)) {echo "<p><font face=\"Dotum\">Your message has been successfully delivered!</font></p>";} else {echo "<p><font face=\"Dotum\">Your message failed to deliver...</font></p>";}?><form name="sendinfo" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"><input name="email" value="<?php echo"$email"?>" type="text" size="30" maxlength="50" /><input class="button" name="submit" type="submit" /> </form>[/code]This is basically it, next time try search in google first ;) Link to comment https://forums.phpfreaks.com/topic/33439-collect-an-email-address-then-mail-it/#findComment-156552 Share on other sites More sharing options...
magic2goodil Posted January 9, 2007 Share Posted January 9, 2007 [code]<?php$to = $_POST['email'];$from = "[email protected]";$subject = "More Information;$message="";$message_html = $_POST['message'];$boundary = md5(uniqid(time())); $headers ="From:" . $from . "\n";$headers .="Return-Path: " . $from . "\n";$headers .= "MIME-Version: 1.0" ."\n"; $headers .="Content-Type: multipart/alternative; boundary=" . $boundary . "\n\n";$headers .= $message . "\n";$headers .= "--" . $boundary . "\n";$headers .= "Content-Type: text/plain; charset=ISO-8859-1" ."\n";$headers .= "Content-Transfer-Encoding: 8bit". "\n\n";$headers .= $message . "\n";$headers .= "--" . $boundary . "\n";$headers .= "Content-Type: text/HTML; charset=ISO-8859-1" ."\n";$headers .= "Content-Transfer-Encoding: 8bit". "\n\n";$headers .= $message_html . "\n";$headers .= "--" . $boundary . "--\n"; if(mail($to,$subject, '', $headers)) {echo" Email sent to " . $to . " successfully.";}else {echo "There was an error sending the email.";}?>[/code] Link to comment https://forums.phpfreaks.com/topic/33439-collect-an-email-address-then-mail-it/#findComment-156556 Share on other sites More sharing options...
maextra7 Posted January 9, 2007 Author Share Posted January 9, 2007 Hey Thanks very much for the really quick replies! Got it working sort of... I cannot get the message body (email body) to show. When I search in google most of it points to an email script using a specified recipent address which is why I thoguht I would pick someone's brains!I know I have probably done something really silly, anyone able to point me inthe right direction?CheersMel! ???[code]<?php$to = $_POST['email'];$from = "[email protected]"; $subject = heal($_POST['name']); $subject = "Information Testing ".$subject;$message="Testing Message";$message_html = $_POST['message'];$boundary = md5(uniqid(time())); $headers ="From:" . $from . "";$headers .="Return-Path: " . $from . "n";$headers .= "MIME-Version: 1.0" ."n"; $headers .="Content-Type: multipart/alternative; boundary=" . $boundary . "nn";$headers .= $message . "n";$headers .= "--" . $boundary . "n";$headers .= "Content-Type: text/plain; charset=ISO-8859-1" ."n";$headers .= "Content-Transfer-Encoding: 8bit". "nn";$headers .= $message . "n";$headers .= "--" . $boundary . "n";$headers .= "Content-Type: text/HTML; charset=ISO-8859-1" ."n";$headers .= "Content-Transfer-Encoding: 8bit". "nn";$headers .= $message_html . "n";$headers .= "--" . $boundary . "--n"; if(mail($to,$subject, '', $headers)) {echo" Email sent to " . $to . " successfully.";}else {echo "There was an error sending the email.";} function heal($str) { $injections = array('/(\n+)/i', '/(\r+)/i', '/(\t+)/i', '/(%0A+)/i', '/(%0D+)/i', '/(%08+)/i', '/(%09+)/i' ); $str= preg_replace($injections,'',$str); return $str; } ?><form name="sendinfo" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"><fieldset><legend id="legend">For more info please enter your email address</legend><br /><input name="email" value="<?php echo"$email"?>" type="text" size="30" maxlength="50" /><input type="submit" name="submit" value="Submit" id="submit" /> <input class="button" name="reset" type="reset" /></fieldset></form>[/code] Link to comment https://forums.phpfreaks.com/topic/33439-collect-an-email-address-then-mail-it/#findComment-156629 Share on other sites More sharing options...
magga Posted January 9, 2007 Share Posted January 9, 2007 In the mail() part you have $to,$subject and then '' which would be the body. You need to put some content in there or a variable which you then need to specify elsewhere in the page. Link to comment https://forums.phpfreaks.com/topic/33439-collect-an-email-address-then-mail-it/#findComment-156648 Share on other sites More sharing options...
maextra7 Posted January 11, 2007 Author Share Posted January 11, 2007 This works brillaintly - thanks to all of you that replied for your help! ;D Link to comment https://forums.phpfreaks.com/topic/33439-collect-an-email-address-then-mail-it/#findComment-158156 Share on other sites More sharing options...
ted_chou12 Posted January 11, 2007 Share Posted January 11, 2007 hey, ive got a question, does these:$headers ="From:" . $from . "";$headers .="Return-Path: " . $from . "n";$headers .= "MIME-Version: 1.0" ."n"; $headers .="Content-Type: multipart/alternative; boundary=" . $boundary . "nn";$headers .= $message . "n";$headers .= "--" . $boundary . "n";$headers .= "Content-Type: text/plain; charset=ISO-8859-1" ."n";$headers .= "Content-Transfer-Encoding: 8bit". "nn";$headers .= $message . "n";$headers .= "--" . $boundary . "n";$headers .= "Content-Type: text/HTML; charset=ISO-8859-1" ."n";$headers .= "Content-Transfer-Encoding: 8bit". "nn";$headers .= $message_html . "n";$headers .= "--" . $boundary . "--n"; these headers work? do you get a message that you have for $from, or is it your hosts email? Link to comment https://forums.phpfreaks.com/topic/33439-collect-an-email-address-then-mail-it/#findComment-158218 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.