Definition-Designs Posted May 18, 2009 Share Posted May 18, 2009 Im not sure if this is an error on my E-Mail account end, or a problem with my code. Im a bit of a novice to PhP, and downloaded a Contact form script from the web, and played around with it a little. Now when the 'Submit' button is clicked, it echo's that the message has been sent, yet I do not recieve it in my e-mail account. Is this my account's fault, or a problem with my php? This is my code, I know it CAN be more efficient, but I will clean it up when it works. Thanks. <?php # PHP Copyright 2007, Thomas Boutell and Boutell.Com, Inc. # Edited by Definition Designs. $recipient = '[email protected]'; $serverName = 'www.definition-designs.co.uk'; if ($_POST['send']) { sendMail(); } elseif (($_POST['cancel']) || ($_POST['continue'])) { redirect(); } else { displayForm(false); } function displayForm($messages) { global $login; $escapedEmail = htmlspecialchars($_POST['email']); $escapedRealName = htmlspecialchars($_POST['realname']); $escapedSubject = htmlspecialchars($_POST['subject']); $escapedBody = htmlspecialchars($_POST['body']); $returnUrl = $_POST['returnurl']; if (!strlen($returnUrl)) { $returnUrl = $_SERVER['HTTP_REFERER']; if (!strlen($returnUrl)) { $returnUrl = '/'; } } $escapedReturnUrl = htmlspecialchars($returnUrl); ?> <html> <head> <title>Definition Designs - Web and Graphics Design</title> <meta name="Author" content="Joshua Martin" /> <meta name="Description" content="Definition Designs is the website of Web and Graphic Designer Joshua Martin" /> <link href="/stylesheet.css" rel="stylesheet" type="text/css"/> <script type="text/javascript" src="/rollover.js"></script> </head> <body onLoad="MM_preloadImages('http://www.definition-designs.co.uk/Images/homeover.png')"> <div id="header"> <img src="http://www.definition-designs.co.uk/Images/header.png"/> </div> <div id="navigation"> <a href="http://www.definition-designs.co.uk/index.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Home','','http://www.definition-designs.co.uk/Images/homeover.png',1)"><img src="http://www.definition-designs.co.uk/Images/homenotover.png" border="0" name="Home" id="Home" /></a> <a href="http://www.definition-designs.co.uk/about.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('About','','http://www.definition-designs.co.uk/Images/aboutover.png',1)"><img src="http://www.definition-designs.co.uk/Images/aboutnotover.png" border="0" name="About" id="About" /></a> <a href="http://www.definition-designs.co.uk/portfolio.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Portfolio','','http://www.definition-designs.co.uk/Images/portfolioover.png',1)"><img src="http://www.definition-designs.co.uk/Images/portfolionotover.png" border="0" name="Portfolio" id="Portfolio"/></a> <a href="http://www.definition-designs.co.uk/contact.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Contact','','http://www.definition-designs.co.uk/Images/contactover.png',1)"><img src="http://www.definition-designs.co.uk/Images/contactnotover.png" border="0" name="Contact" id="Contact"/></a> </div> <div id="mainContent2"> <div id="MailForminfo"> To contact me for a question, or to request one of my services, please fill out the contact form to the left.<br> <br> I will try to reply as soon as possible. <br> <br> Websites can take from 1 week to 1 month to create depending on the order, with Graphic design being more varied. </div> <div id="MailForm"> <?php if (count($messages) > 0) { $message = implode("<br>\n", $messages); echo("<h3>$message</h3>\n"); } ?> <form method="POST" action="<?php echo $_SERVER['DOCUMENT_URL']?>"> <p> <b>Your</b> Email Address <input name="email" size="35" maxlength="35" value="<?php echo $escapedEmail?>"/> </p> <p> Your <b>Real</b> Name <input name="realname" size="35" maxlength="35" value="<?php echo $escapedRealName?>"/> </p> <p> Subject Of Your Message <input name="subject" size="35" maxlength="35" value="<?php echo $escapedSubject?>"/> </p> <p> <i>Please enter the text of your message in the field that follows.</i> </p> <textarea name="body" rows="10" cols="60"><?php echo $escapedBody?></textarea> <p> <input type="submit" name="send" value="Send Your Message"/> <input type="submit" name="cancel" value="Cancel - Never Mind"/> </p> <input type="hidden" name="returnurl" value="<?php echo $escapedReturnUrl?>"/> </form> </body> </html> <?php } function redirect() { global $serverName; $returnUrl = $_POST['returnurl']; $prefix = "http://$serverName/"; if (!beginsWith($returnUrl, $prefix)) { $returnUrl = "http://$serverName/"; } header("Location: $returnUrl"); } function beginsWith($s, $prefix) { return (substr($s, 0, strlen($prefix)) === $prefix); } function sendMail() { global $recipient; $messages = array(); $email = $_POST['email']; if (!preg_match("/^[\w\+\-\.\~]+\@[\-\w\.\!]+$/", $email)) { $messages[] = "That is not a valid email address. Perhaps you left out the @something.com part? "; } $realName = $_POST['realname']; if (!preg_match("/^[\w\ \+\-\'\"]+$/", $realName)) { $messages[] = "The real name field must contain only alphabetical characters, numbers, spaces, and the + and - signs. We apologize for any inconvenience. "; } $subject = $_POST['subject']; $subject = preg_replace('/\s+/', ' ', $subject); if (preg_match('/^\s*$/', $subject)) { $messages[] = "Please specify a subject for your message. "; } $body = $_POST['body']; if (preg_match('/^\s*$/', $body)) { $messages[] = "Your message was blank. Did you mean to say something? Click the Cancel button if you do not wish to send a message. "; } if (count($messages)) { displayForm($messages); return; } if (mail($recipitent, $subject, $body, "From: $realName <$email>")) { echo("<p>Message successfully sent!</p>"); } else { echo("<p>Message delivery failed...</p>"); } $escapedReturnUrl = htmlspecialchars($_POST['returnurl']); ?> <html> <head> <title>Thank You</title> </head> <body> <h1>Thank You</h1> <p> Thank you for contacting us! Your message has been sent. </p> <form method="POST" action="<?php echo $_SERVER['DOCUMENT_URL']?>"> <input type="submit" name="continue" value="Click Here To Continue"/> <input type="hidden" name="returnurl" value="<?php echo $escapedReturnUrl?>"/> </form> <?php } ?> </div> </div> </body> </html> Link to comment https://forums.phpfreaks.com/topic/158615-solved-mail-not-being-sent-to-account-on-submit/ Share on other sites More sharing options...
mattal999 Posted May 18, 2009 Share Posted May 18, 2009 Spelling mistakes. Tut, tut. Here: <?php $recipient = '[email protected]'; ?> And you mail it to $recipitent (should be $recipient). Modded code below: <?php if (mail($recipient, $subject, $body, "From: $realName <$email>")) { // Was $recipitent } ?> Link to comment https://forums.phpfreaks.com/topic/158615-solved-mail-not-being-sent-to-account-on-submit/#findComment-836547 Share on other sites More sharing options...
Definition-Designs Posted May 18, 2009 Author Share Posted May 18, 2009 nope. is still isn't sending anything. Link to comment https://forums.phpfreaks.com/topic/158615-solved-mail-not-being-sent-to-account-on-submit/#findComment-836555 Share on other sites More sharing options...
Definition-Designs Posted May 19, 2009 Author Share Posted May 19, 2009 i really need help with this Link to comment https://forums.phpfreaks.com/topic/158615-solved-mail-not-being-sent-to-account-on-submit/#findComment-837338 Share on other sites More sharing options...
mrMarcus Posted May 19, 2009 Share Posted May 19, 2009 you try echo'ing out $subject, $email, etc., to see that they're set? Link to comment https://forums.phpfreaks.com/topic/158615-solved-mail-not-being-sent-to-account-on-submit/#findComment-837395 Share on other sites More sharing options...
Definition-Designs Posted May 19, 2009 Author Share Posted May 19, 2009 } if (mail($recipient, $subject, $body, "From: $realName, $email")) { echo("<p>Message successfully sent!</p>"); echo("<p>$subject</p>"); echo("<p>$body</p>"); echo("<p>From: $realName, $email</p>"); echo("To: $recipient"); } else { echo("<p>Message delivery failed...</p>"); } I changed to code to that, filled it in, clickd submit and got this: Message successfully sent! Test This is a 'echo' test. From: Joshua Martin, [email protected] To: [email protected] I cant see why this is not sending! EDIT: It doesnt seem to be a problem with the account itself, as I can send mail from my hotmail to this account.. Link to comment https://forums.phpfreaks.com/topic/158615-solved-mail-not-being-sent-to-account-on-submit/#findComment-837473 Share on other sites More sharing options...
Definition-Designs Posted May 19, 2009 Author Share Posted May 19, 2009 Turns out it was my web hosting provider. They do not allow SMTP, so I shall be changing! Thanks for the help anyway, guys! Link to comment https://forums.phpfreaks.com/topic/158615-solved-mail-not-being-sent-to-account-on-submit/#findComment-837501 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.