duanci9305 2013-05-16 23:19
浏览 165
已采纳

通过PHP发送注册表单结果到电子邮件地址[关闭]

I have a question about PHP email function, I hope you can help me with this. I have little to no experience in PHP.

Ive set up a web page, where users can submit following info via the HTML form: Name, Email, Phone, and couple Drop Down Selectors.

I have created an empty form.php and when clicked on submit, it gets connected to that php file. Thing is, I want the results to be mailed to my email address WIHOUT mysql database, as far as I know this is possible with PHP, but I couldnt find any tutorial for this.

Can you give me any pointers or guides please, how can I do it ?

Thanks in advance Cheers : ))

EDIT: I forgot to mention, with some PHP tutorials, I managed to send the mail to my email address, and managed to get the email subject correctly, but I couldnt get the results of email in the body of the email sent, body is always empty.

Can you please give me an example script, how I could get the results of this form in the body of message? Most tutorials show how to get $message in the body, but I dont really have any text to send via $message. I simply have couple text fields and couple drop down selectors.

  • 写回答

2条回答 默认 最新

  • dqlm80253 2013-05-17 00:13
    关注

    Just try this:

    <?php
    $to = "someone@example.com";
    $subject = "Test mail";
    $message = "Hello! This is a simple email message.";
    $from = "someonelse@example.com";
    $headers = "From:" . $from;
    
    if(mail($to,$subject,$message,$headers)){
    echo "Mail Sent.";}
    else{
    echo "Mail not sent";
    }
    ?>
    

    EDIT: 1: soneonelse@example.com; and 'someonelse@example.com are just two different email, like it mentions about the sender and the receiver of the email So, make sure to change the email I have given above to the email you want to send.

    2: If you want to style <div> then do something like this:

     echo "<div style='color:white; background-color:red; font-size:14px; padding:20px; 
     border:1px solid black;'> Mail Sent</div>";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化