我正在尝试使用php创建联系表单。当我点击发送时,电子邮件似乎已发送但收件人从未真正收到它。也许我需要设置一个SMTP服务器,但我不确定如何做到这一点。提前致谢
在form.html中我有
<form action="mail.php" method="POST">
<p>Name</p> <input type="text" name="name">
<p>Email</p> <input type="text" name="email">
<p>Phone</p> <input type="text" name="phone">
<p>Request Phone Call:</p>
Yes:<input type="checkbox" value="Yes" name="call"><br />
No:<input type="checkbox" value="No" name="call"><br />
<p>Website</p> <input type="text" name="website">
<p>Priority</p>
<select name="priority" size="1">
<option value="Low">Low</option>
<option value="Normal">Normal</option>
<option value="High">High</option>
<option value="Emergency">Emergency</option>
</select>
<br />
<p>Type</p>
<select name="type" size="1">
<option value="update">Website Update</option>
<option value="change">Information Change</option>
<option value="addition">Information Addition</option>
<option value="new">New Products</option>
</select>
<br />
<p>Message</p><textarea name="message" rows="6" cols="25"></textarea><br />
<input type="submit" value="Send"><input type="reset" value="Clear">
</form>
在mail.php文件中我有
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$call = $_POST['call'];
$website = $_POST['website'];
$priority = $_POST['priority'];
$type = $_POST['type'];
$message = $_POST['message'];
$formcontent=" From: $name \n Phone: $phone \n Call Back: $call \n Website: $website \n Priority: $priority \n Type: $type \n Message: $message";
$recipient = "kerrip90@hotmail.co.uk";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!" . " -" . "<a href='form.html' style='text- decoration:none;color:#ff0099;'> Return Home</a>";
?>
答案 0 :(得分:1)
要使mail()
函数正常工作,您只需在服务器上安装postfix,方法是发出以下命令:
sudo apt-get install postfix
答案 1 :(得分:0)
您可以试用pear
包。
sudo apt-get install pear
sudo pear install mail
安装程序也会推荐其他几个软件包。以相同的方式安装它们。要发送邮件使用:
public function sendMail($to)
{
require_once('Mail.php');
$this->_to=$to;
$host = "ssl://smtp.gmail.com";
$port = "465";
$headers = array ('From' => $this->_from,
'To' => $this->_to,
'Subject' => $this->_subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $this->_username,
'password' => $this->_password));
$mail = $smtp->send($this->_to, $headers, $this->_body);
}