html - PHP mail() won't send when included in other PHP file with user input email -
i generating page of information database. need send email page content reminder. (example here takes input message) takes in email address , supposed send details address.
<div class="container"> <?php $name = $_get['info']; if(isset($name)){ $info = explode('|', $name); /***************************************************** open conection mysql database ******************************************************/ .... /***************************************************** populate page ******************************************************/ $sql="select information table"; $result = mysqli_query($con,$sql); while($row = mysqli_fetch_array($result)) { /*title*/ echo '<h1>'.$row['post_title'].'</h1><hr>'; /*content*/ echo '<h2>details: </h2><br>'.$row['post_content'].'<br>'; $content = $row['post_title']; /*reminder*/ echo '<div data-role="collapsible"> <h1>send reminder</h1>'; include("includes/email_reminder.php"); echo'</div>'; } /***************************************************** close connection ******************************************************/ mysqli_close($con); } else { echo'nothing selected. go <br> <a href="#" data-rel="back"> <img src="img/icon/back.png" style="height: 3em" > </a>'; } ?> </div> that creates form @ bottom of page take in email needs needs reminder. email_reminder.php:
<?php function spamcheck($field) { // sanitize e-mail address $field=filter_var($field, filter_sanitize_email); // validate e-mail address if(filter_var($field, filter_validate_email)) { return true; } else { return false; } } ?> <?php // display form if user has not clicked submit if (!isset($_post["submit"])) { ?> <form method="post" action="<?php echo $_server["php_self"];?>"> email: <input type="text" name="to"><br> subject: <input type="text" name="subject"><br> message: <textarea rows="10" cols="40" name="message"></textarea><br> <input type="submit" name="submit" value="submit feedback"> </form> <?php } else // user has submitted form { // check if "from" input field filled out if (isset($_post["to"])) { // check if "from" email address valid $receivecheck = spamcheck($_post["to"]); if ($receivecheck==false) { echo "invalid input"; } else { $to = $_post["to"]; //receiver $subject = $_post["subject"]; $message = $_post["message"]; // message lines should not exceed 70 characters (php rule), wrap $message = wordwrap($message, 70); // send mail mail("$to",$subject,$message,"from: myaddress@mail.com\n"); echo "reminder has been sent"; } } } ?> i have used form in isolation (just opened email_reminder.php on own) , sent emails correctly whichever email address used. doesn't send when included in other script.
include(emai_reminder.php); needs single quotes surrounding file name (and email correctly spelled: include('email_reminder.php');
but, looks need more this. example, there no field from in form, although reference $_post["from"]. you're running validation against variable, doesn't exist, fails validation, prevents else if block running, prevents mail() ever being called.
Comments
Post a Comment