我是 PHP 新手,拼命想在我的网站上获取一个简单的联系表格,以便使用 swiftmailer 工作。所以我将库安装到正确的位置,表单打开如下:
<form action="mailhandler_girls.php" method="post" enctype="multipart/form-data">
然后在我的“mailhandler_girls.php”文件中,我有以下内容:
<?php
$_SESSION["post"] = $_POST;
$name = $_POST["Name"]; $email = $_POST["Email"]; $phone = $_POST["Phone"]; $dob = $_POST['DOBDay'] ."\t" .$_POST['DOBMonth'] ."\t" .$_POST['DOBYear'];$address = $_POST['AddressLine1'] ."\n" .$_POST['AddressLine2'] ."\n" .$_POST['PostCode'];$experience = $_POST["Experience"];$height = $_POST["Height"]; $size = $_POST["DressSize"];$bra = $_POST["Bra"];$waist = $_POST["Waist"];$hipwidest = $_POST["HipWidest"];$bicep = $_POST["Bicep"];$thigh = $_POST["Thigh"];$shoe = $_POST["Shoe"];
require_once 'lib/swift_required.php';
// Create the Transport
$transport = Swift_SmtpTransport::newInstance('auth.smtp.1and1.co.uk', 25)
->setUsername('user@example.com')
->setPassword('test')
;
// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
// Create a message
$message = Swift_Message::newInstance('Be A Model application: Girls')
// Set the From address with an associative array
->setFrom(array('$email' => '$name'))
// Set the To addresses with an associative array
->setTo(array('holla@emilekelly.com', 'contact@emilekelly.com' => 'contact test'))
// Give it a body
->setBody('Name: ' .$name ."\n"
.'Email: ' .$email ."\n"
.'Phone: ' .$phone ."\n"
.'Address: ' .$address ."\n"
.'DOB: ' .$dob ."\n"
.'Experience: ' .$experience ."\n"
.'Height: ' .$height ."\n"
.'Dress Size: ' .$size ."\n"
.'Bra: ' .$bra ."\n"
.'Waist: ' .$waist ."\n"
.'Hip at Widest: ' .$hipwidest ."\n"
.'Bicep: ' .$bicep ."\n"
.'Thigh: ' .$thigh ."\n"
.'Shoe Size: ' .$shoe ."\n" )
// And optionally an alternative body
->addPart('<q>Here is the message itself</q>', 'text/html');
// Send the message
$result = $mailer->send($message);
?>
什么都没发生。我确定我做错了什么是显而易见的,但我迷失在其中。我一直在使用文档,它让我走到了这一步,但仍然卡住了。
我只想让这个基本版本正常工作,然后担心使用图像附件进行详细说明。我也对 SMTP 传输感到困惑。像这样将用户名和密码放在网络上的文件中肯定不是一个好主意吗?