douao3636 2012-03-18 01:54
浏览 22
已采纳

如何使用smtp设置告诉朋友脚本?

I trying to make a tell a friend script.

The script must send an email to the address the user specifies in the form field. containing the link of the current page in the mail body.

I tried a lot of scripts and mail classes like phpmailer, etc..

But couldnt make any of them works...

Can someone help me?

UPDATE: this is my current code

<?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>

it works, but the script is activated when loading the page (return a recipient error), how can i make the script run only when user press the submit button?

  • 写回答

2条回答 默认 最新

  • duanmei2805 2012-03-18 02:15
    关注

    Pear Mail is pretty easy to use if it's available to you

    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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了
  • ¥100 H5网页如何调用微信扫一扫功能?
  • ¥15 讲解电路图,付费求解
  • ¥15 有偿请教计算电磁学的问题涉及到空间中时域UTD和FDTD算法结合的
  • ¥15 three.js添加后处理以后模型锯齿化严重
  • ¥15 vite打包后,页面出现h.createElement is not a function,但本地运行正常