【问题标题】:Getting swiftmailer to work让 swiftmailer 工作
【发布时间】:2013-03-18 10:29:08
【问题描述】:

我是 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 传输感到困惑。像这样将用户名和密码放在网络上的文件中肯定不是一个好主意吗?

【问题讨论】:

  • 所以没有 SMTP 用户名和密码你怎么能使用它。??
  • 设置php_ini('display_errors', true);error_reporting(E_ALL);,转储信息:var_dump($result);,如果你有bug,我们会找到他。
  • 什么,怎么样?对不起,正如我所说,我知道这一切..

标签: php html forms swiftmailer


【解决方案1】:

好的,既然您是新手,请先尝试使用预定义的值而不是命令行中的 $_POST 执行 php 文件。

如果您在 Windows 上,则必须遍历您的目录并执行以下操作:

php.exe mailhandler_girls.php

如果您使用的是 linux,请执行以下操作:

php5 mailhandler_girls.php 

如果有任何错误,这将优雅地输出。

错误消息将指示您的凭据是否存在问题、加密问题或其他问题。

【讨论】:

    猜你喜欢
    • 2016-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-06
    • 2014-03-11
    • 2010-09-27
    • 2016-04-29
    相关资源
    最近更新 更多