music_fan01 Posted September 2, 2011 Share Posted September 2, 2011 I have my php form made and I tested just sending emails to my email on my webhost and it worked. I just now made my contact form for my site, but I've spotted a few things that I am not sure how to change because I was going by an old example that I had that sends emails out to an email address with a message already sent. I am going for the opposite. I want to user to be able to put in their name, email address, along with a personalized message that gets sent to my email address. This is the first time I've done something like this before and any help is appreciated. Thanks! <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>Contact</title> </head> <body> <?php $to = "starr@gmail.com"; $from = " <no-reply@sitename.info >"; $headers = "MIME-Version: 1.0\r\n"; $headers.= "Content-type: text/html; charset=iso-8859-1\r\n"; $headers.= "From: $from\r\n"; $mail_body = "Hello World"; if (mail($to,"Mail", $mail_body,$headers)) { echo " Thank you! - Your feedback has been sent! "; } else { echo " Thank you! - We could not send email. Please try later! "; } ?> </body> </html> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Contact</title> <link href="style.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="templatemo_wrapper"> <div id="templatemo_header"> <ul id="social_box"> <li><a href="http://www.facebook.com/"><img src="images/facebook.png" alt="facebook" /></a></li> <li><a href="http://www.twitter.com/"><img src="images/twitter.png" alt="twitter" /></a></li> </ul> <div id="site_title"> <h1><a href="index.htm"><img src="images/logo2.png" alt="logo" /><span></span></a></h1> </div> <!-- end of site_title --> </div> <!-- end of templatemo_header --> <div id="templatemo_menu"> <div class="home"><a href="index.htm"></a></div> <ul> <li><a href="contact.htm"><span>Contact</span></a></li> </ul> </div> <!-- end of templatemo_menu --> <div id="templatemo_content_wrapper"> <div id="templatemo_content_top"></div> <div id="templatemo_content"> <h2>Contact</h2> <p><b>E-mail: starr@gmail.com </b></p> <p><b><a href="http://www.twitter.com/">Twitter</a></b></p> <div class="cleaner_h50"></div> <div id="contact_form"> <h4>Quick Contact</h4> <form method="post" name="contact" action="email.php"> <div class="col_w340 float_l"> <label for="namer">Name:</label> <input name="name" type="text" class="input_field" id="author" maxlength="40" /> <div class="cleaner_h10"></div> <label for="email">Email:</label> <input name="email" type="text" class="input_field" id="email" maxlength="40" /> <div class="cleaner_h10"></div> </div> <div class="col_w340 float_r"> <label for="text">Message:</label> <textarea id="text" name="text" rows="0" cols="0" class="required"></textarea> <div class="cleaner_h10"></div> <input type="submit" class="submit_btn float_l" name="submit" id="submit" value="Send" /> <input type="reset" class="submit_btn float_r" name="reset" id="reset" value="Reset" /> </div> </form> </div> <div class="cleaner"></div> </div> <div id="templatemo_content_bottom"></div> </div> <div id="templatemo_sp_box"> <div class="col_w340 float_l"> </div> </div> <div class="col_w340 float_r"> </div> </div> </div> <div id="templatemo_footer"> Copyright © 2011 <a href="www.twitter.com/starr">Starr</a><br/> <a href="http://www.iwebsitetemplate.com" target="_parent">Website Templates</a> by <a href="http://www.templatemo.com" target="_parent">Free CSS Templates</a> </div> <!-- end of templatemo_footer --> </div> <!-- end of templatemo_wrapper --> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/246237-php-contact-form-achieved-but-doesnt-work/ Share on other sites More sharing options...
music_fan01 Posted September 2, 2011 Author Share Posted September 2, 2011 And when I run it, I get my message that it sent the message, but I never get the email. Quote Link to comment https://forums.phpfreaks.com/topic/246237-php-contact-form-achieved-but-doesnt-work/#findComment-1264581 Share on other sites More sharing options...
flappy_warbucks Posted September 2, 2011 Share Posted September 2, 2011 Depends if the server you're using is set up to send emails. The mail() function kinda needs the SMTP part of the server. If you're not sure, then just throw together a script that can connect to a known SMTP server (like your gmail address) and then send it via that. I would not put (even as a testing site) to much faith in the mail() function. I have heard to many horror stories. Quote Link to comment https://forums.phpfreaks.com/topic/246237-php-contact-form-achieved-but-doesnt-work/#findComment-1264588 Share on other sites More sharing options...
music_fan01 Posted September 2, 2011 Author Share Posted September 2, 2011 This is what I tested on my host and worked fine. <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>Email Page</title> </head> <body> <?php $to = "starr@gmail.com"; $subject = "Test"; $body = "Test messages"; $headers = "From: starr2005@yahoo.com\n"; mail($to,$subject,$body,$headers); echo "Mail sent to $to"; ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/246237-php-contact-form-achieved-but-doesnt-work/#findComment-1264593 Share on other sites More sharing options...
Drummin Posted September 2, 2011 Share Posted September 2, 2011 Note sure that mail() is being executed within the IF condition. You might try this. mail($to,"Mail", $mail_body,$headers) if (mail($to,"Mail", $mail_body,$headers)){ et c Quote Link to comment https://forums.phpfreaks.com/topic/246237-php-contact-form-achieved-but-doesnt-work/#findComment-1264614 Share on other sites More sharing options...
cyberRobot Posted September 2, 2011 Share Posted September 2, 2011 And when I run it, I get my message that it sent the message, but I never get the email. How long did you wait for the e-mail? Sometimes it may not be instant. Maybe the mail server is backed-up? Are the messages being caught by your spam filter? Quote Link to comment https://forums.phpfreaks.com/topic/246237-php-contact-form-achieved-but-doesnt-work/#findComment-1264695 Share on other sites More sharing options...
music_fan01 Posted September 2, 2011 Author Share Posted September 2, 2011 As of now, its been 24 hours and still nothing and I've checked my spam folder. Quote Link to comment https://forums.phpfreaks.com/topic/246237-php-contact-form-achieved-but-doesnt-work/#findComment-1264779 Share on other sites More sharing options...
music_fan01 Posted September 3, 2011 Author Share Posted September 3, 2011 I got my contact form working, I just now would like to tweak it a bit. First, when I send a test email, in my inbox I get (unknown sender) I would like to change that to the persons name (preferably first and last name. Currently I have it set up with name thinking people will put in both.) Another thing that I want to achieve, is that also when I send a test email to my inbox, I want to be able to hit reply in my inbox and the users email shows up and I can reply to them without having to put the email in myself on my side. Finally, I would like to add a captcha code to avoid spam emails. Thanks! <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Contact</title> <link href="style.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="templatemo_wrapper"> <div id="templatemo_header"> <ul id="social_box"> <li><a href="http://www.facebook.com/"><img src="images/facebook.png" alt="facebook" /></a></li> <li><a href="http://www.twitter.com/><img src="images/twitter.png" alt="twitter" /></a></li> </ul> <div id="site_title"> <h1><a href="index.htm"><img src="images/logo2.png" alt="logo" /><span></span></a></h1> </div> <!-- end of site_title --> </div> <!-- end of templatemo_header --> <div id="templatemo_menu"> <div class="home"><a href="index.htm"></a></div> <ul> <li><a href="index.htm"><span>Home</span></a></li> <li><a href="test.htm"><span>Test</span></a></li> <li><a href="example.htm"><span>Examples</span></a></li> <li><a href="gallery.htm"><span>Gallery</span></a></li> <li><a href="contact.htm"><span>Contact</span></a></li> <li><a href="comments.htm">Have A Comment?<span>Comments</span></a></li> </ul> </div> <!-- end of templatemo_menu --> <div id="templatemo_content_wrapper"> <div id="templatemo_content_top"></div> <div id="templatemo_content"> <h2>Contact</h2> <p><b>E-mail: starr@gmail.com </b></p> <p><b><a href="http://www.twitter.com/">Twitter</a></b></p> <div class="cleaner_h50"></div> <div id="contact_form"> <h4>Quick Contact</h4> <form method="post" name="contact" action="email.php"> <div class="col_w340 float_l"> <label for="namer">Name:</label> <input name="name" type="text" class="input_field" id="author" maxlength="40" /> <div class="cleaner_h10"></div> <label for="subject">Subject:</label> <input name="subject" type="text" class="input_field" id="subject" maxlength="40" /> <div class="cleaner_h10"></div> <label for="email">Email:</label> <input name="email" type="text" class="input_field" id="email" maxlength="40" /> <div class="cleaner_h10"></div> </div> <div class="col_w340 float_r"> <label for="text">Message:</label> <textarea id="text" name="text" rows="0" cols="0" class="required"></textarea> <div class="cleaner_h10"></div> <input type="submit" class="submit_btn float_l" name="submit" id="submit" value="Send" /> <input type="reset" class="submit_btn float_r" name="reset" id="reset" value="Reset" /> </div> </form> </div> <div class="cleaner"></div> </div> <div id="templatemo_content_bottom"></div> </div> <div id="templatemo_sp_box"> <div class="col_w340 float_l"> </div> </div> <div class="col_w340 float_r"> </div> </div> </div> <div id="templatemo_footer"> Copyright © 2011 <a href="www.twitter.com/">Starr</a><br/> <a href="http://www.iwebsitetemplate.com" target="_parent">Website Templates</a> by <a href="http://www.templatemo.com" target="_parent">Free CSS Templates</a> </div> <!-- end of templatemo_footer --> </div> <!-- end of templatemo_wrapper --> </body> </html> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Contact</title> <link href="style.css" rel="stylesheet" type="text/css" /> </head> <body> <?php $first_name=$_POST['name']; $email_address=$_POST['email']; $subject=$_POST['subject']; $message=$_POST['text']; mail("starr@gmail.com","Subject: $subject", $message, "From: $email"); echo "Thank you for using our mail form.<br/>"; echo "Your email has been sent."; ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/246237-php-contact-form-achieved-but-doesnt-work/#findComment-1264964 Share on other sites More sharing options...
music_fan01 Posted September 3, 2011 Author Share Posted September 3, 2011 http://www.thewebhelp.com/php/scripts/php-contact-form-with-image-validation/ This is kind of what I am going for with my contact form. Quote Link to comment https://forums.phpfreaks.com/topic/246237-php-contact-form-achieved-but-doesnt-work/#findComment-1265000 Share on other sites More sharing options...
cyberRobot Posted September 5, 2011 Share Posted September 5, 2011 I got my contact form working, I just now would like to tweak it a bit. First, when I send a test email, in my inbox I get (unknown sender) I would like to change that to the persons name (preferably first and last name. Example #4 on the PHP Manual page for mail() should guide you in the right direction: http://php.net/manual/en/function.mail.php Quote Link to comment https://forums.phpfreaks.com/topic/246237-php-contact-form-achieved-but-doesnt-work/#findComment-1265494 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.