开发者

My PHP form with an html <select> box that sends form to different emails isn't executing

I'm still new to php, so i'm sure it's a stupid mistake here somewhere, but I can't figure out why my form is not being sent to any of the emails i've assigned in the user box. I thought it'd just be a simple "if" statement but when i hit submit on the form, as far as i can tell, it goes nowhere. It doesn't even execute. Take a look at my code and see if you see any syntax problems or something:

<?php
$hostname  =  "db.example.com";
$database  =  "poweri3_blank";
$username   =  "script";
$password   =  "xxxxxx";
$conn  =   mysql_connect($hostname, $username, $password) or DIE("Unable to connect to database"); 
$dbconnection  =  $conn;
mysql_select_db($database) OR DIE("Unable to select database");

/* Subject and Email Variables- */
$emailSubject = 'Request for Provider'; 
$webMaster = 'me@gmail.com'; 

/*Gathering Data Variables*/
$firstName  =  $_POST['firstName'];
$lastName  =  $_POST['lastName'];
$email  =  $_POST['email'];
$zipCode = $_POST['zipCode'];
$provider = $_POST['provider'];
$comment = $_POST['comment'];

//send e-mail to differ开发者_如何学JAVAent providers
if($provider=="p1") $sendTo = "p1@gmail.com";
if($provider=="p2") $sendTo = "p2@gmail.com";
if($provider=="p3") $sendTo = "p3@gmail.com";
if($provider=="p4") $sendTo = "p4@gmail.com";

$body = <<<EOD
<br><hr><br>//--------CONTACT--------//<br><br>
Name: $firstName $lastName<br><br>
Email: $email<br><br>
Cable or Satellite Provider: $provider<br><br>
Zip/Postal Code: $zipCode<br><br>
Your Message: $comment<br><br>
EOD;

$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster,$emailSubject,$body,$headers);

//Enter Data Into Table
$sql = "INSERT INTO poweri3_blank.provider_contact (
            firstName,
            lastName,
                        email,
                        zip_code, 
                        provider, 
                        comment                       
            )
        VALUES(
            '".$firstName."',
            '".$lastName."',
                        '".$email."',
                        '".$zipCode."',
                        '".$provider."',
                        '".$comment."')";

$result  =  mysql_query($sql) or die("Couldn't execute query: $sql");
//$result  =  mysql_query($sql) or die(mysql_error());

// Kill connection
mysql_close($conn);

/*Results rendered as HTML


$theResults = <<<EOD
<html>
<head>
<title>Yourpage title</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
body {
background-color: #f1f1f1;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
font-style: normal;
line-height: normal;
font-weight: normal;
color: #666666;
text-decoration: none;
}
-->
</style>
</head>

<div>
<div align="left">Thank You For Your Interest. </div>
</div>
</body>
</html>
EOD;


echo "$theResults";*/
?>

I'm working in MODx if anyone is wondering. Thanks. Sorry, i wouldn't normally ask but i'm completely lost. If the page was erroring out, it'd be one thing, but it just isn't doing anything (as far as i can tell).


I'm not sure what the point of your

//send e-mail to different providers
if($provider=="p1") $sendTo = "p1@gmail.com";
if($provider=="p2") $sendTo = "p2@gmail.com";
if($provider=="p3") $sendTo = "p3@gmail.com";
if($provider=="p4") $sendTo = "p4@gmail.com";

is since you don't seem to use the $sendTo at all later in the script.

If you want to know if it is doing anything use some echo statements, including one on the $success variable. if(!$success) echo "error"; or something.

Also, what errors are being thrown at the moment?


Did you mean $success = mail($sendTo,$emailSubject,$body,$headers); ?


$success = mail($webMaster,$emailSubject,$body,$headers);

should be

$success = mail($sendTo,$emailSubject,$body,$headers);

If you are using mail function, you need to setup SMTP in your server.

If you don't know how to setup , try with PHPMailer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜