如何在php中发送HTML动态表作为邮件? [英] How to send HTML Dynamic Table as mail in php?

查看:124
本文介绍了如何在php中发送HTML动态表作为邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里我有一个代码,例如从index.php获取数据,如果用户输入的数据将显示为表格,以及它应该去电子邮件到一些预定义的邮件。但是我在动态地获取数据,我尝试使用$ _REQUEST和$ _POST两种方法来获取数据,但是在邮件功能中,我正在尝试更改消息参数,但是通过php标签,它没有采取并显示一些语法错误。 p>

请在这里查看代码

 <?php 
$到= xxxxxxx@gmail.com;
$ fn =Fisrt Name;
$ ln =姓氏;
$ name = $ fn。''$ ln;
$ from =xxxxx@xxx.com;
$ subject =欢迎来到网站;

include('newsmtp / smtpwork.php');

?>
<?php

$ message ='亲爱的$ firstName,


您的欢迎讯息''
< table边界= 1>

< tr>
< td>名字:< / td>
< td><?php $ firstName = $ _ POST ['firstname'];
echo $ firstName;?>< / td>
< / tr>

< tr>
< td>姓:< / td>
< td><?php $ lastname = $ _ POST ['lastname'];
echo $ lastname;?>< / td>

< / tr>

< tr>

< td>标题:< / td>
< td><?php $ title = $ _ POST ['title'];
echo $ title;?>< / td>
< / tr>

< tr>

< td>地址:< / td>
< td><?php $ address = $ _ POST ['address'];
echo $ address;?>< / td>
< / tr>

< tr>

< td>电话号码:< / td>
< td><?php $ phone = $ _ POST ['phone'];
echo $ phone;?>< / td>
< / tr>


< tr>

< td>课程名称:< / td>
< td><?php $ course = $ _ POST ['coursename'];
echo $ course;?>< / td>

< / tr>

< tr>

< td>网站:< / td>
< td><?php $ website = $ _ POST ['website'];
echo $ website;?>< / td>

< / tr>

< / table>

感谢
xxxxxxxxxxxx
';
?>


解决方案

尝试这种方法,将发布的值分配给变量, $ message变量外部打印$ message变量$ / $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $
$ lastname = $ _POST ['lastname'];
$ title = $ _POST ['title'];
$ address = $ _POST ['address'];
$ phone = $ _POST ['phone'];
$ course = $ _POST ['course'];
$ website = $ _POST ['website'];


$ message ='Dear'。$ firstName。',
您的欢迎讯息''
< table border = 1>
< tr>
< td>名字:< / td>
< td>'。$ firstname。'< / td>
< / tr>
< tr>
< td>姓:< / td>
< td>'。$ lastname。'< / td>
< / tr>
< tr>
< td>标题:< / td>
< td>'。$ title。'< / td>
< / tr>
< tr>
< td>地址:< / td>
< td>'。$ address。'< / td>
< / tr>
< tr>
< td>电话号码:< / td>
< td>'。$ phone。'< / td>
< / tr>
< tr>
< td>课程名称:< / td>
< td>'。$ course。'< / td>
< / tr>
< tr>
< td>网站:< / td>
< td>'。$ website。'< / td>
< / tr>
< / table>
感谢
xxxxxxxxxxxx
';
?>




$ to =xxxxxxx@gmail.com;
$ subject =欢迎来到网站;
$ headers ='From:xxxxxx< noreply@xxxxxxx.com>'。 \r\\\
;
$ headers。=MIME-Version:1.0\r\\\
;
$ headers。=Content-Type:text / html; \\\
\tcharset = \iso-8859-1\\r\\\
;

$ sent = @mail($ to,$ subject,$ message,$ headers);

if($ sent){
return true;
} else {
return false;
}

另外添加必要的标题来发送HTML邮件作为Vinoth Babu,Naveen建议


Here i have a code like getting the data from index.php , if user enter the data it will show like table and as well as it should go to email to some predefined mail. But here i am getting data Dynamically , i tried with $_REQUEST and $_POST both methods to get the data , but in mail function i am trying to change message parameter but by php tags its is not taking and showing some syntax errors.

please go through code here

<?php
$to="xxxxxxx@gmail.com";
$fn="Fisrt Name";
$ln="Last Name";
$name=$fn.' '.$ln;
$from="xxxxx@xxx.com";
$subject = "Welcome to Website";

include('newsmtp/smtpwork.php');

 ?>
 <?php

 $message = 'Dear $firstName, 


 Your Welcome Message.'.'
 <table border=1>

    <tr>
        <td>First Name:</td>
        <td><?php $firstName=$_POST['firstname'];
        echo $firstName;?></td>
    </tr>

    <tr>
        <td>Last Name:</td>
        <td><?php $lastname=$_POST['lastname'];
        echo $lastname;?></td>

    </tr>

    <tr>

        <td>Title:</td>
        <td><?php $title=$_POST['title'];
        echo $title;?></td>
    </tr>

    <tr>

        <td>Address:</td>
        <td><?php $address=$_POST['address'];
        echo $address;?></td>
    </tr>

    <tr>

        <td>Phone Number:</td>
        <td><?php $phone=$_POST['phone'];
        echo $phone;?></td>
    </tr>


    <tr>

        <td>Course Name:</td>
        <td><?php $course=$_POST['coursename'];
        echo $course;?></td>

    </tr>

    <tr>

        <td>Website:</td>
        <td><?php $website=$_POST['website'];
        echo $website;?></td>

    </tr>

</table>

Thanks
xxxxxxxxxxxx
';
?> 

解决方案

Try this method, assign the posted values in variables, outside the $message variable and print the variable inside your $message variable

$firstname  = $_POST['firstname'];
$lastname   = $_POST['lastname'];
$title      = $_POST['title'];
$address    = $_POST['address'];
$phone      = $_POST['phone'];
$course     = $_POST['course'];
$website    = $_POST['website'];


    $message = 'Dear '.$firstName.', 
     Your Welcome Message.'.'
     <table border=1>
        <tr>
            <td>First Name:</td>
            <td>'.$firstname.' </td>
        </tr>
        <tr>
            <td>Last Name:</td>
            <td>'.$lastname.'</td>
        </tr>
     <tr>
        <td>Title:</td>
        <td>'.$title.'</td>
    </tr>
    <tr>
        <td>Address:</td>
        <td>'.$address.'</td>
    </tr>
    <tr>
        <td>Phone Number:</td>
        <td>'.$phone.'</td>
    </tr>
    <tr>
        <td>Course Name:</td>
        <td>'.$course.'</td>
    </tr>
    <tr>
        <td>Website:</td>
        <td>'.$website.'</td>
    </tr>
</table>
Thanks
xxxxxxxxxxxx
';
?> 




$to       ="xxxxxxx@gmail.com";
$subject  = "Welcome to Website";
$headers  = 'From: xxxxxx <noreply@xxxxxxx.com>' . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html;\n\tcharset=\"iso-8859-1\"\r\n";

$sent   = @mail($to,$subject,$message,$headers); 

        if ($sent) {
            return true;
        } else {
            return false;
        }

Also add necessary header to send HTML mail as Vinoth Babu, Naveen suggested

这篇关于如何在php中发送HTML动态表作为邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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