用函数发送html邮件 [英] Sending html mail with function

查看:130
本文介绍了用函数发送html邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究这个问题,并且找不到问题。希望有人能够帮助我。

I've been working on this for ages and just can't find the issue. Hope somebody is so kind enough to help me out.

我为我的邮件脚本做了一个函数。这个函数在里面有用.functions.inc.php

I've made a function for my mailing script. The function is inside useful_functions.inc.php

<?php
include ('mailer/class.phpmailer.php');

function sendmail($mail)
{
  $mail = new PHPMailer(true);  

  if (($_SERVER["REQUEST_METHOD"] == "POST") && $geslachtErr== "" && $voornaamErr== "" && $familienaamErr== "" && $emailErr== "" && $telErr== "" && $afileErr== "")
  {
    $full_name  = "Sofie Doe";
    $email      = "sofie@gmail.com";
    $subject    = "HTML test mail.";
    $text_message    = "Hello ".$full_name.",<br /><br /> This is a test email in html.";         

    $message  = "<html><body>";

    $message .= "<table width='100%' bgcolor='#e0e0e0' cellpadding='0' cellspacing='0' border='0'>";

    $message .= "<tr><td>";

    $message .= "<table align='center' width='100%' border='0' cellpadding='0' cellspacing='0' style='max-width:650px; background-color:#fff; font-family:Verdana, Geneva, sans-serif;'>";

    $message .= "<thead>
          <tr height='80'>
            <th colspan='4' style='background-color:#f5f5f5; border-bottom:solid 1px #bdbdbd; font-family:Verdana, Geneva, sans-serif; color:#333; font-size:34px;' >TEST</th>
          </tr>
          </thead>";


    $message .= "</table>";

    $message .= "</td></tr>";
    $message .= "</table>";

    $message .= "</body></html>";

    try
    {
      $mail->IsSMTP(); 
      $mail->isHTML(true);
      $mail->SMTPDebug  = 0;                     
      $mail->SMTPAuth   = true;                  
      $mail->SMTPSecure = "STARTTLS";                 
      $mail->Host       = "mailout.one.com";      
      $mail->Port       = 587;             
      $mail->AddAddress($email);
      $mail->Username   ="joe@gmail.com";  
      $mail->Password   ="Password";            
      $mail->SetFrom("joe@gmail.com");
      $mail->AddReplyTo("joe@gmail.com");
      $mail->Subject    = $subject;
      $mail->Body     = $message;
      $mail->AltBody    = $message;
    }
  }
}

?>

我有一个表单, test.php 。我用

I have a form, test.php. I start them test.php with

<?php
include ('useful_functions.inc.php')
sendmail($mail);
?>

当我运行 test.php 时,我保留得到HTTP错误500

When I run test.php I keep getting HTTP ERROR 500

我用一个简单的html表单测试了确切的邮件程序,并以相同的方式调用它,并且它可以工作。
我的 test.php 在我删除 sendmail($ mail)时起作用, code> useful_function.inc.php

I've tested the exact mailer with a simple html form and calling it the same way and it works. My test.php works when I remove sendmail($mail) and remove the function in my useful_function.inc.php

为什么这不起作用?

Why is this not working?

推荐答案

为什么你不通过修改 try {} 来包含 $ mail->发送();

Why don't you have the email "send itself" by modifying try{} to include $mail->Send();?

您的尝试将变为:

Your "try" will become:

try
{
  $mail->IsSMTP(); 
  $mail->isHTML(true);
  $mail->SMTPDebug  = 0;                     
  $mail->SMTPAuth   = true;                  
  $mail->SMTPSecure = "STARTTLS";                 
  $mail->Host       = "mailout.one.com";      
  $mail->Port       = 587;             
  $mail->AddAddress($email);
  $mail->Username   ="joe@gmail.com";  
  $mail->Password   ="Password";            
  $mail->SetFrom("joe@gmail.com");
  $mail->AddReplyTo("joe@gmail.com");
  $mail->Subject    = $subject;
  $mail->Body     = $message;
  $mail->AltBody    = $message;
  $mail->Send();
  echo "Message Sent OK\n";
  } catch (phpmailerException $e) {
    echo $e->errorMessage(); //Pretty error messages from PHPMailer
  } catch (Exception $e) {
    echo $e->getMessage(); //Boring error messages from anything else!
  }

这篇关于用函数发送html邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆