dongrong9053 2014-08-28 17:14
浏览 80
已采纳

1and1上的php电子邮件表单

I am trying to combine the name field with the email field so that the email will be delivered like:

From: Name of Person Filling Out Form (email_address.com)

Goal: (Email From Line would contain the person's name and email).

I am using 1and1's mail.php function and there are no instructions on how to do this.

Is this even possible?

Here is my code:

<?php

echo '<link href="new/css/style.css" rel="stylesheet">';

// THE BELOW LINE STATES THAT IF THE SUBMIT BUTTON
// WAS PUSHED, EXECUTE THE PHP CODE BELOW TO SEND THE 
// MAIL. IF THE BUTTON WAS NOT PRESSED, SKIP TO THE CODE
// BELOW THE "else" STATEMENT (WHICH SHOWS THE FORM INSTEAD).
if ( isset ( $_POST [ 'buttonPressed' ] )){

// REPLACE THE LINE BELOW WITH YOUR E-MAIL ADDRESS.
$to = 'myemail.com' ;
$subject = 'From PHP contact page' ;

// NOT SUGGESTED TO CHANGE THESE VALUES
$message = $_POST [ "message" ] ;
$headers = 'From: ' . $_POST[ "from" ] . PHP_EOL ;
$name = $_POST['name'];
mail ( $to, $subject, $message, $headers ) ;

// THE TEXT IN QUOTES BELOW IS WHAT WILL BE 
// DISPLAYED TO USERS AFTER SUBMITTING THE FORM.

echo '<div id="msg_sent"> Your e-mail has been sent. You should receive a reply within a week. </div>';}

?>

Thank you if you know anything!

  • 写回答

1条回答 默认 最新

  • doujinai2183 2014-08-28 17:21
    关注

    "I am using 1and1's mail.php function and there are no instructions on how to do this.
    Is this even possible?"

    Yes, it is possible.

    Add an email form element <input type="text" name="email"> if you don't already have one, then do:

    $email   = $_POST['email'];
    $name    = $_POST['name'];
    $headers = "From: ". $name . " <" . $email . ">
    ";
    

    Mail stands at going to Spam if the From is only a name, instead of containg an Email address.

    You should also use FILTER_VALIDATE_EMAIL for your email variable, in order to validate it.

    I.e.:

    if(!filter_var($email, FILTER_VALIDATE_EMAIL))
      {
      echo "E-mail is not valid.";
      }
    

    Sidenote:
    Rocket's comments make sense in regards to PHP_EOL which is why my example contains .

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测