Jump to content

Recommended Posts

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!');
}

?>

Link to comment
https://forums.phpfreaks.com/topic/228959-php-emailing-help/
Share on other sites

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. 

Link to comment
https://forums.phpfreaks.com/topic/228959-php-emailing-help/#findComment-1180153
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.