January 3, 201412 yr Hi all, It has been a while since iv done any php and im trying to make a simple textboook mail form but cant see what im doing wrong. <form action="" method="post"> Want us to call you? <input type="text" placeholder = "Please enter a contact number" class="callBackField" name="callBackField"> <input type="submit" value="Call me back" class="callBackSubmit"> </form> <?php if (isset($_POST['callBackSubmit'])) { $to = "dgeorge@live.co.uk"; $subject = "Call me back, Guild Bathrooms"; $message = $_POST['callBackField']; $from = "mail.guildbathrooms.com"; mail($to,$subject,$message); echo "Mail Sent."; } ?> the action field is left blank because the php is on the same page as the html, im pretty sure i have done something wrong in the php, any help would ne greatly appreciated. Thanks for looking Best regards David
January 3, 201412 yr 1. Although setting the form action to nothing will theoretically work I have found that not all servers will accept this. Setting the action to: <?php echo htmlentities($_SERVER['PHP_SELF']); ?> or <?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?> Will solve the issue. Note: Most modern servers will default to one of these methods automatically if the action is set to <?php echo $_SERVER['PHP_SELF']; ?> 2. You are not setting any headers to the mail function. Many servers will not allow a mail to send if it is not from an email on that domain: You have a $from variable: $from = "mail.guildbathrooms.com"; $headers = "From: $from"; Try <?php if (isset($_POST['callBackSubmit'])) { $to = "xxxxxxx@livexxxx.co.uk"; $subject = "Call me back, Guild Bathrooms"; $message = $_POST['callBackField']; $from = "mail.guildbathrooms.com"; $headers = "From: $from"; mail($to,$subject,$message;$headers); echo "Mail Sent."; } ?> Edited January 3, 201412 yr by nfc212
Create an account or sign in to comment