Jump to content

Php emailing help


Collegeboox

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 = "[email protected]";
$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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.