YousefDiab Posted August 20, 2014 Share Posted August 20, 2014 <?php $site_email = $row["example@madhost.co"]; $email25=$_REQUEST['email']; $action=$_REQUEST['action']; if ($action=="") /* display the contact form */ { ?> <form id="ContactForm" action="" method="POST" enctype="multipart/form-data"> <input type="hidden" name="action" value="submit"> <div> <div class="wrapper"> <span>Your Name:</span> <input type="text" class="input" name="name" maxlenght="15"> </div> <div class="wrapper"> <span>Your E-mail:</span> <input type="text" class="input" name="email" > </div> <div class="textarea_box"> <span>Your Message:</span> <textarea name="textarea" cols="1" rows="1"></textarea> </div> <input type="submit" class="button1"> <a href="contact.php" class="button1">Clear</a> </div> </form> <?php } else /* send the submitted data */ { $name=$_REQUEST['name']; $email=$_REQUEST['email']; $message=$_REQUEST['textarea']; if (($name=="")||($email=="")||($message=="")) { echo "All fields are required, please fill <a href=\"\">the form</a> again."; } else{ $from="From: $name<$email>\r\nReturn-path: $email"; $subject= $subject1; mail($to =$site_email, $message, $from); echo " <div class=\"contactform\"> Thank you for contacting us, please wait for our reply! </div> "; } } ?> The only problem is that im not recieving the email :/ Any Help ? I would really appreciate it and thank you Quote Link to comment https://forums.phpfreaks.com/topic/290549-php-mail-not-sending/ Share on other sites More sharing options...
ginerjm Posted August 20, 2014 Share Posted August 20, 2014 (edited) your mail statement has an error in it? Edited August 20, 2014 by ginerjm Quote Link to comment https://forums.phpfreaks.com/topic/290549-php-mail-not-sending/#findComment-1488401 Share on other sites More sharing options...
BuildMyWeb Posted August 20, 2014 Share Posted August 20, 2014 (edited) try something more like the below else { $from = "From: $name<$email>\r\nReturn-path: $email"; $subject = "Form Submission"; $to = "youremail@yahoo.com"; $message = "you likely will want to loop through your $_POST variables here"; mail($to, $subject, $message); echo" <div class=\"contactform\"> Thank you for contacting us, please wait for our reply! </div> "; } there is also an option fourth parameter in the mail() function. preferable to use it well if you dont want your emails being dropped in spam folders, blocked, etc. Edited August 20, 2014 by BuildMyWeb Quote Link to comment https://forums.phpfreaks.com/topic/290549-php-mail-not-sending/#findComment-1488432 Share on other sites More sharing options...
AP_King7 Posted August 20, 2014 Share Posted August 20, 2014 How do you loop through POST variables there? Quote Link to comment https://forums.phpfreaks.com/topic/290549-php-mail-not-sending/#findComment-1488442 Share on other sites More sharing options...
AP_King7 Posted August 20, 2014 Share Posted August 20, 2014 (edited) For instance how would I put this into $message? <?php $aMeat = $_POST['tMeat']; if(empty($aMeat)) { echo("You didn't select any meats."); } else { $N = count($aMeat); echo("You ordered $N meat(s): "); for($i=0; $i < $N; $i++) { echo($aMeat[$i] . " - ").; } } ?> Edited August 20, 2014 by AP_King7 Quote Link to comment https://forums.phpfreaks.com/topic/290549-php-mail-not-sending/#findComment-1488443 Share on other sites More sharing options...
CroNiX Posted August 20, 2014 Share Posted August 20, 2014 Problem is you're echoing the values, which will just go out to the browser. You want to add it to a string. $aMeat = $_POST['tMeat']; $message = ''; if(empty($aMeat)) { $message = "You didn't select any meats."; } else { $N = count($aMeat); $message = "You ordered $N meat(s): "; for($i=0; $i < $N; $i++) { //add this meat to the end of the $message string (string concatenation) $message .= $aMeat[$i] . " - "; } } Quote Link to comment https://forums.phpfreaks.com/topic/290549-php-mail-not-sending/#findComment-1488445 Share on other sites More sharing options...
CroNiX Posted August 20, 2014 Share Posted August 20, 2014 alternatively, since $aMeat is an array, you can use implode() on it, like $N = count($aMeat); $message = "You ordered $N meat(s): " . implode(', ', $aMeat); Message would now be something like: You ordered 1 meat(s): pork or if there were more than one selected: You ordered 3 meat(s): pork, beef, chicken Quote Link to comment https://forums.phpfreaks.com/topic/290549-php-mail-not-sending/#findComment-1488446 Share on other sites More sharing options...
AP_King7 Posted August 20, 2014 Share Posted August 20, 2014 I need all of the information to go into the browser as well. I have it all set up to echo to the browser and it works perfectly, now I just need to send all of the different arrays in an e-mail message. How do I echo them to the browser and add them to my message? Also, I am wanting to add more than just meats, I have other variables similar to $aMeat that I want to add in the message, is that possible this way? Quote Link to comment https://forums.phpfreaks.com/topic/290549-php-mail-not-sending/#findComment-1488448 Share on other sites More sharing options...
BuildMyWeb Posted August 20, 2014 Share Posted August 20, 2014 $name = $_POST['name']; $email = $_POST['email']; $to = "youremail@yahoo.com"; $subject = "submission data"; $fields = array(); $fields["Name"] = $name; $fields["Email"] = $email; $message = "We have received the following information from a submission:\n\n"; foreach($fields as $a => $b) { $message .= sprintf("%30s: %s\n",$a,$b); } mail($to, $subject, $message); Quote Link to comment https://forums.phpfreaks.com/topic/290549-php-mail-not-sending/#findComment-1488449 Share on other sites More sharing options...
ginerjm Posted August 20, 2014 Share Posted August 20, 2014 I do believe that the mail function requires the headers to be in the 4th (missing) parameter. For one thing you absolutely have to provide a from address there. Quote Link to comment https://forums.phpfreaks.com/topic/290549-php-mail-not-sending/#findComment-1488452 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.