With a contact form, a customer usually fills in their information and email etc., and when they click Send, an email is sent to you.
通过联系表格,客户通常会填写他们的信息和电子邮件等,当他们点击发送时,会向您发送一封电子邮件。
However, I need a form where it sends the email to the email that is populated in the "Email" field.
但是,我需要一个表单,将电子邮件发送到填写在“电子邮件”字段中的电子邮件。
I have to send tracking information daily to customers and would like to do it from this form instead of an email client.
我必须每天向客户发送跟踪信息,并希望从此表单而不是电子邮件客户端进行。
<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="name" 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>
I do not know how to do the final part where the SEND function fires the correct way. If anyone can help with that please.
我不知道如何在SEND函数触发正确方法的最后部分。如果有人可以提供帮助请。
1 个解决方案
#1
3
I would solve this with the use of Swiftmailer. The form would look like the followning:
我会用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>
Then the 'send.php' would look like:
然后'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 you can download from here: http://swiftmailer.org/download (just unzip to the same path as send.php) Documentation of Swiftmailer is here: http://swiftmailer.org/docs/introduction.html
您可以从这里下载Swiftmailer:http://swiftmailer.org/download(只需解压缩到与send.php相同的路径)Swiftmailer的文档在这里:http://swiftmailer.org/docs/introduction.html
Hope it helps!
希望能帮助到你!
#1
3
I would solve this with the use of Swiftmailer. The form would look like the followning:
我会用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>
Then the 'send.php' would look like:
然后'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 you can download from here: http://swiftmailer.org/download (just unzip to the same path as send.php) Documentation of Swiftmailer is here: http://swiftmailer.org/docs/introduction.html
您可以从这里下载Swiftmailer:http://swiftmailer.org/download(只需解压缩到与send.php相同的路径)Swiftmailer的文档在这里:http://swiftmailer.org/docs/introduction.html
Hope it helps!
希望能帮助到你!