Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/243.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP PEAR Mail发送2封电子邮件_Php_Html_Email_Pear - Fatal编程技术网

PHP PEAR Mail发送2封电子邮件

PHP PEAR Mail发送2封电子邮件,php,html,email,pear,Php,Html,Email,Pear,此脚本可以工作,但访问时会发送一封空白电子邮件。然后提交一个真实的。我想去掉它发送的第一个空白的。这主要是我在这里找到的经过编辑的代码,也是我根据需要拼凑起来的另一个地方 <?php ini_set("include_path", '/home/user/php:' . ini_get("include_path") ); require_once "Mail.php"; $first_name = $_POST['first_name']; $last_name = $_POST['l

此脚本可以工作,但访问时会发送一封空白电子邮件。然后提交一个真实的。我想去掉它发送的第一个空白的。这主要是我在这里找到的经过编辑的代码,也是我根据需要拼凑起来的另一个地方

<?php
ini_set("include_path", '/home/user/php:' . ini_get("include_path") );
require_once "Mail.php";

$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email = $_POST['email'];
$address = $_POST['address'];
$phone = $_POST['phone'];
$contact = $_POST['contact'];
$comments = $_POST['comments'];
$from = "Info <info@domain.net>";
$to = "Info <info@domain.net>";
$subject = "Customer Contact Form";
$body = "If this works it will be edited a bit \n" . "First Name: " . $first_name . "\n" . "Last Name: " . $last_name . "\n" . "Email: " . $email . "\n" . "Address: " . $address . "\n" . "Phone: " . $phone . "\n" . "Please contact me by: " . $contact . "\n" . "Other Comments: " . $comments;

$host = "mail.domain.net";
$username = "info@domain.net";
$password = "emailpassword";

$headers = array ('From' => $from,
    'To' => $to,
    'Subject' => $subject);
$smtp = Mail::factory('smtp',
    array ('host' => $host,
        'auth' => true,
        'username' => $username,
        'password' => $password));

$mail = $smtp->send($to, $headers, $body);

//if (PEAR::isError($mail)) {
//  echo("<p>" . $mail->getMessage() . "</p>");
//} else {
//  echo("<p>Message successfully sent!</p>");
//}
?>

<!DOCTYPE html>
<head>
<title>Form submission</title>
</head>
<body>

<form action="" method="post">
First Name: <input type="text" name="first_name"><br>
Last Name: <input type="text" name="last_name"><br>
Email: <input type="text" name="email"><br>
Address: <input type="text" name="address"><br>
Phone: <input type="text" name="phone"><br>
Perferred Form of Contact: <input type="text" name="contact"><br> 
Message:<br><textarea rows="5" name="comments" cols="30"></textarea><br>
<input type="submit" name="submit" value="Submit">
</form>

</body>
</html>

提交表格
名字:
姓氏:
电子邮件:
地址:
电话:
最佳联系方式:
信息:


因为您没有检查表单数据!
只需在生成和发送邮件的代码周围使用一个简单的
if(isset($\u POST['first\u name'))
,如果您已经发送了表单,它将只发送一封电子邮件。

谢谢。如果其他人想知道,他的代码会在$headers前面加上一个[和另一个],正好在注释掉的内容之前。