我正在尝试配置 Swift Mailer 以将表单数据发送到我的电子邮件帐户简而言之:我有一个网站,我将使用该网站在我当地的城市出售一些东西当“购买”按钮时出现 3 个简单的表单活动的重点是发送数据,这些表格直接填写到我的电子邮件帐户,作为PHP的新手,我尝试了几天来使这个简单的脚本工作,但它最终失败了这里是邮件的代码。 php:
<?php
$name=$_POST["name"];
$email=$_POST["email"];
$phone=$_POST["phone"];
if (isset ($name))
{
$name = substr($name,0,30);
if (empty($name))
{
echo "<center><b>Invalid name<p>";
echo "<a href=index.php>Come back and fill up the form properly</a>";
exit;
}
}
else
{
$name = "Invalid name";
}
if (isset ($email))
{
$email = substr($email,0,30); //Не может быть более 20 символов
if (empty($email))
{
echo "<center><b>Email Invalid!<p>";
echo "<a href=index.php>Try again</a>";
exit;
}
}
else
{
$email = "Invalid";
}
if (isset ($phone))
{
$phone = substr($phone,0,15);
if (empty($phone))
{
echo "<center><b>Empty message!!!<p>";
echo "<a href=index.php>Try again</a>";
exit;
}
}
else
{
$phone = "invalid";
}
$i = "invalid";
if ($name == $i AND $email == $i AND $phone == $i)
{
echo "Error! No data was transferred to the script";
exit;
}
$to = "zakaz@playpad2.ru";
$subject = "New order ";
$message = "Name:$name::::::::::Email:$email::::::::::Phone No:$phone:::::::::;
require_once 'lib/swift_required.php';
$transport = Swift_SmtpTransport::newInstance('smtp.yandex.ru', 465, 'ssl')
->setUsername('zakaz@playpad2.ru')
->setPassword('jhfy;tdjtujdyj');
$mailer = Swift_Mailer::newInstance($transport);
// Create a message
$message = Swift_Message::newInstance('Wonderful Subject')
->setFrom(array('kirabidzu@gmail.com' => 'PlayPad 2 Kids tablet order'))
->setTo(array('zakaz@playpad2.ru', 'zakaz@playpad2.ru' => 'A name'))
->setBody('Name:$name::::::::::Email:$email::::::::::Phone No:$phone:::::::::');
// Send the message
$numSent = $mailer->send($message);
if (!$numSent) {
print "Can't send a message";
}
echo "<center><b>Thank you<a href=index.php>Proceed</a> to continue...>";
exit;
?>"
这是一个表格,位于主页上:
<form name="form" action="mail.php" method="POST"><b>Name here </b>
<br> <input type="text" size="70%" name="name" maxlength="45"> <br>
<b>Phone No </b>
<br> <input type="text" size="70%" name="phone" maxlength="15"> <br>
<b>E-Mail </b>
<br> <input type="text" size="70% " name="email" maxlength="45"> <br>
<input type="submit"><div class="button"></div>
请帮忙!
更改了 smtp 服务器端口,并出现新错误:PHP 致命错误:未捕获异常 'Swift_TransportException',消息为 'Expected response code 250 but got code "553",消息为 "553 5.7.1 Sender address denied: notowned by auth user .\r\n"' 如果邮件是从站点发送的,A 无法理解为什么我需要“发件人”字段??这个人只是填写了表格,我想收到一封包含他或她填写的数据的电子邮件?我应该在“发件人”字段中写什么?
UPD:终于发送电子邮件了!!!刚刚使“发件人”和“收件人”电子邮件地址相等 感谢大家的帮助