2011-09-19 62 views
0

我还是新来的PHP,所以我敢肯定这是一个愚蠢的错误在这里某处,但我不明白为什么我的表单未被发送到我在用户框中分配的任何电子邮件。我认为这只是一个简单的“if”陈述,但当我在表单上提交时,据我所知,它无处可去。它甚至不执行。看看我的代码,看看如果你看到任何语法问题或东西:我的PHP表单与HTML <select>框发送表单到不同的电子邮件没有执行

<?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 = '[email protected]'; 

/*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 different providers 
if($provider=="p1") $sendTo = "[email protected]"; 
if($provider=="p2") $sendTo = "[email protected]"; 
if($provider=="p3") $sendTo = "[email protected]"; 
if($provider=="p4") $sendTo = "[email protected]"; 

$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";*/ 
?> 

我在镆铘工作,如果你想知道。谢谢。对不起,我通常不会问,但我完全失去了。如果页面出错,这将是一回事,但它只是没有做任何事情(据我所知)。

+2

建议您更改数据库密码,如果这是您在问题中发布的真实密码。 –

+0

@Jbarnet你可以给我发电子邮件在保罗在elphin.com?我有一些建议给你... –

回答

0

我不知道你的

//send e-mail to different providers 
if($provider=="p1") $sendTo = "[email protected]"; 
if($provider=="p2") $sendTo = "[email protected]"; 
if($provider=="p3") $sendTo = "[email protected]"; 
if($provider=="p4") $sendTo = "[email protected]"; 

的一点是什么,因为你似乎并不在所有后来在脚本中使用$ SENDTO。

如果您想知道它是否在做任何事情,请使用一些echo声明,其中包括$success变量中的一个。 if(!$success) echo "error";什么的。

此外,此刻正在抛出什么错误?

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

应该

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

如果使用邮件功能,你需要设置SMTP在你的服务器。

如果您不知道如何设置,请尝试PHPMailer

0

您的意思是 $success = mail($sendTo,$emailSubject,$body,$headers);

相关问题