duanhao1004 2014-04-05 11:12
浏览 677
已采纳

尝试将表单数据发送到我的电子邮件

I have a basic html form on my website and I'm wanting the data entered into the form to be sent to my email once submitted, after submit button pressed I'm taken to the "Sent.html" which just displays a sent message on-screen, but when i check the email account I have not received the email..

HTML Form....

<form name="contactform" method="POST" action="formphp.php">

<table width="450px">
<tr>
    <td valign="top">
    <label for="name">Name *</label>
</td>
    <td valign="top">
    <input  type="text" name="Name" maxlength="50" size="30">
</td>
</tr>
<tr>

    <td valign="top"">

    <label for="email">Email *</label>
</td>
    <td valign="top">
    <input  type="text" name="Email" maxlength="50" size="30">
</td>
</tr>

<td valign="top">

    <label for="subject">Subject *</label>
</td>
    <td valign="top">
    <input  type="text" name="Subject" maxlength="50" size="30">
</td>
</tr>

<tr>
    <td valign="top">
    <label for="questions">Question/Feedback *</label>
</td>
    <td valign="top">
    <textarea name="Question" cols="40" rows="5"></textarea>
</td>
</tr>

<tr>
    <td colspan="2" style="text-align:center">
    <input type="submit" value="Submit">
</td>
</tr>
</table>
</form>

PHP code...

<?php
/* set email */
$myemail = "dcmagpies@hotmail.co.uk";

/* declare id */
$Name = $_POST['Name'];
$Email = $_POST['Email'];
$subject = $_POST['Subject'];
$Questions = $_POST['Questions'];

/* set subject heading */
$subject = "Subject";

/* Message */
$message = "$Name + $Email + $Questions

";

/* redirect this form after email sent */
header("location: sent.html");
?>
  • 写回答

3条回答 默认 最新

  • duanjian3338 2014-04-05 11:26
    关注

    Try using PHPMailer library: https://github.com/PHPMailer/PHPMailer

    $mail = new PHPMailer(true); 
    
    $html = '
    <!DOCTYPE html>
    <html>
    <head>
        <title>Contact</title>
    </head>
    <body>
        CONTENT HERE
    </body>
    </html>
    ';
    
    try {
        $mail->AddAddress('info@domain.com', 'Domain Name');
        $mail->SetFrom('info@domain.com', 'Domain Name');
        $mail->Subject = 'Contact from domain.com';
        $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; 
        $mail->MsgHTML($html);
        if(!$mail->send()) {
           echo 'Message could not be sent.';
           echo 'Mailer Error: ' . $mail->ErrorInfo;
           exit;
        }else{
           header("location: sent.html");
        }
    } catch (phpmailerException $e) {
        echo $e->errorMessage(); //Pretty error messages from PHPMailer
    } catch (Exception $e) {
        echo $e->getMessage(); //Boring error messages from anything else!
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题