Collegeboox Posted February 26, 2011 Share Posted February 26, 2011 I am trying to have a form that is filled out through the a website email me with the info the entered...the code is below, the problem is when you hit send it goes the the next page which says email was sent but no email is sent... CODE.... <?php $firstname = $_POST['firstname']; $question = $_POST['question']; $username = $_SESSION['username']; if ($_POST['submit']) { //connect to database $connect = mysql_connect("db","user","pass") or die("Not connected"); mysql_select_db("user") or die("could not log in"); //grab email from database $query = "SELECT * FROM table WHERE username='$username'"; $result = mysql_query($query); $row = mysql_fetch_array($result); //set email to variable name $email = $row['email']; //set SMTP $server = "smtp.gmail.com"; ini_set("SMTP",$server); //setup variables $to = "Collegebooxstore@gmail.com"; $subject = "Member Contact Us"; $body = "This is an email from $firstname\n\n email $email\n\n\n $question"; $headers = "From: $email"; //existance check if ($firstname&&$question) { mail($to, $subject, $body, $headers); } else die('Please make sure your filled in your firstname as well as a Quesiton/Comment!'); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/228959-php-emailing-help/ Share on other sites More sharing options...
jcbones Posted February 26, 2011 Share Posted February 26, 2011 First try wrapping your email function in an if statement, this will tell you if an error occurred with the function. if(!mail($to, $subject, $body, $headers)) { trigger_error('Mail Function Failed'); } Next: Are you on a shared host? Does your host allow emails from accounts not hosted on their server. Most shared host does not. Which means that your FROM header must have an account that resides on the SMTP server. Quote Link to comment https://forums.phpfreaks.com/topic/228959-php-emailing-help/#findComment-1180153 Share on other sites More sharing options...
Collegeboox Posted February 27, 2011 Author Share Posted February 27, 2011 I am using godaddy, and emails used to send they have stopped recently, I do not know if I changed the code or something...I put your function in the brackets after the mail function that I had {mail(...)Your code} Quote Link to comment https://forums.phpfreaks.com/topic/228959-php-emailing-help/#findComment-1180214 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.