dqrzot2791 2015-06-17 15:49
浏览 16
已采纳

php表单邮件功能

I am using a mail function to mail it to my email adress, but i want it to send me a message with variables in it. (I have tried to concatenate it with concatenation point, but it doesn't seem to work, or I did not use it right)

The code:

<?php

$myEmail = "lol@lol.com";
$emailOnderwerp = "Contact form";
$naam = $_POST['naam'];
$email = $_POST['email'];
$onderwerp = $_POST['onderwerp'];
$bericht = $_POST['bericht'];
$mail1 = "<h1>";
$mail2 = "</h1><h2>Afzender:</h2><p>";
$mail3 = " (";
$mail4 = ")</p><h2>Bericht:</h2><p>";
$mail5 = "</p>";

mail("$myEmail","$emailOnderwerp",MESSAGE,"Content-type:text/html; charset=iso-8859-1"."
"."From:info@aikodedoncker.donboscohalle.net");
?>

I know MESSAGE is not supposed to be there, it is just to make it easy to see that the message needs to be placed there.

So I want the message to be $mail1 + $onderwerp + $mail2 + $naam + $mail3 + ...

How can I achieve this?

  • 写回答

2条回答 默认 最新

  • dqwr32867 2015-06-17 16:22
    关注

    As I mentioned in comments, you're overthinking this and there are a few simpler ways to go about this.

    Either by changing your whole block to: (no need for all those variables)

    $mail = "
    
    <h1>
    </h1><h2>Afzender:</h2><p>
     (
    )</p><h2>Bericht:</h2><p>
    </p>
    
    ";
    

    then

    mail("$myEmail","$emailOnderwerp",$mail,...
    

    But, if you wish to continue using what you have now:

    You can concatenate in a few ways, such as:

    $mail = $mail1 . "" . $mail2 . "" . $mail3 . "" . $mail4 . "" . $mail5;
    

    or

    $mail = "$mail1 $mail2 $mail3 $mail4 $mail5";
    

    Sidenote:

    You're missing a closing semi-colon for:

    mail($myEmail,"$emailOnderwerp",$message,...")
    

    which would throw a parse error, if that is your actual code.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像