【问题标题】:How can i set up a tell a friend script using smtp?如何使用 smtp 设置告诉朋友脚本?
【发布时间】:2012-04-03 01:33:05
【问题描述】:

我正在尝试制作一个告诉朋友的脚本。

脚本必须向用户在表单字段中指定的地址发送电子邮件。包含邮件正文中当前页面的链接。

我尝试了很多脚本和邮件类,如 phpmailer 等。

但无法使它们中的任何一个起作用......

有人可以帮我吗?

更新:这是我当前的代码

<?php
require_once 'Mail.php';

$from = "xxx@xxxx.com.";

$to = $_POST["email"];
$subject = "Pear mail test";
$body = "testing pear mail. if you are reading this, it is working.";

$host = "smtp.xxxxxx.com";

$username = "xxx@xxxx.com.";
$password = "xxxxx";

$headers = array ('From' => $from,
  'To' => $to,
  'Subject' => $subject);

$smtp = Mail::factory('smtp',
  array ('host' => $host,
  'port' => '587',
    'auth' => true,
    'username' => $username,
    'password' => $password));
$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {
  echo("<p>" . $mail->getMessage() . "</p>");
 } else {
  echo("<p>Message successfully sent!</p>");
 }
 ?>

<form action="<?php echo $PHP_SELF?>" method="post">
<fieldset>
        <legend>Recomendar</legend>
         <label for="nome">Nome</label><input name="nome" size="40" type="text" />
         <label for="email">E-mail:</label><input name="email" size="40" type="text" />
         <input type="submit" value="Enviar" />
</fieldset>
</form>

它可以工作,但是在加载页面时脚本被激活(返回收件人错误),我怎样才能让脚本仅在用户按下提交按钮时运行?

【问题讨论】:

  • 您确定运行脚本的服务器支持 SMTP 连接吗?我在尝试使用 mail() 时遇到了同样的问题。
  • 如果您自己的主机不允许邮寄,您可以设置一个 gmail 帐户从应用程序发送邮件。
  • 我的主机允许 smtp,我使用 smtp 处理我网站的其他邮件功能。
  • 你为什么不回答我的问题就拒绝我的问题.. B.S..

标签: php email smtp


【解决方案1】:

如果您可以使用 Pear Mail,它非常易于使用

http://pear.php.net/manual/en/package.mail.mail.factory.php

$headers = array
  ( "Subject" => $subj,
    "To" => $to,
    "From" => "Your Name <{$from}>",
    "Content-Type" => "text/plain",
    "MIME-Version" => "1.0"
    );

$message = "Hello, world";

$smtp = Mail::factory
  ( "smtp",
    array
    ( "host" => "???",
      "port" => 465,
      "auth" => true,
      "username" => $from,
      "password" => $pass
     )
    );

$mail = $smtp->send($to, $headers, $message);

【讨论】:

  • 谢谢你工作得很好,谢谢你的回答,不要像那些无缘无故否决我的问题的 6 个白痴那样行事......
  • 不客气……不能代表那些不愿意提供帮助的人。我不明白。
【解决方案2】:

尝试输入

php 邮件

进入上面的搜索框。已经发布了很多好东西 - 例如, herehere。正如 dldnh 所说,Pear Mail 很好。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-05-05
    • 1970-01-01
    • 2012-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多