我会使用 Swiftmailer 来解决这个问题。表单如下所示:
<form method="POST" action="send.php">
<div id="form">
<div id="name">
<p id="username"> Name: </p>
<input type="text" name="name" class="textfield">
</div>
<div id="name">
<p id="username"> Email: </p>
<input type="text" name="email" class="textfield">
</div>
<div id="name">
<p id="username"> Message: </p>
<input type="text" name="message" class="textarea">
</div>
<input type="button" value="SEND" id="btn">
</div>
</form>
然后'send.php'看起来像:
<?php
require_once 'lib/swift_required.php';
$transport = Swift_SmtpTransport::newInstance('smtp.google.com', 465, 'ssl')
->setUsername('mail@gmail.com')
->setPassword('your password');
$mailer = Swift_Mailer::newInstance($transport);
$name = $_POST['name'];
$emailTo = $_POST['email'];
$message = $_POST['message'];
$message = Swift_Message::newInstance('Your subject goes here')
->setFrom(array('yourmail@here.com' => 'Your name here'))
->setTo(array($emailTo => $name))
->setBody($message);
$result = $mailer->send($message);
if ( $result > 0 )
{
//Email was sent
}
else
{
// Email was not sent
}
?>
Swiftmailer 您可以从这里下载:http ://swiftmailer.org/download (只需解压缩到与 send.php 相同的路径) Swiftmailer 的文档在这里:http ://swiftmailer.org/docs/introduction.html
希望能帮助到你!