首页 > 解决方案 > Why is this e-mail form using validation resulting in an error?

问题描述

error i'm getting is "Warning: mail(): "sendmail_from" not set in php.ini or custom "From:" header missing"

  else
  {
      $emailTo ="me@domain.com";
      $subject =$_POST['subject'];
      $content =$_POST['content'];
      $headers = "From : ".$_POST['email'];

      if (mail( $emailTo,  $subject , $content, $headers))
      {
          $successfulMessage ='<div class="alert alert-success" role="alert">Your message is sent,We\'ll get back to you soon </div>' ;
      } 
      else
      {
          $error = '<div class="alert alert-danger" role="alert"><p><strong>Your message coudn\'t be sent</strong></p> </div>' ; 
      }

  }

标签: php

解决方案


Your From header is incorrectly formatted. Change

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

to

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

But I'd suggest something more extensive like in the answer found here: [PHP Warning: mail(): " sendmail_from" not set in php.ini or custom "From:" header missing

And just in case you're not running Unix and encounter the smtp error after this: Failed to connect to mailserver at "localhost" port 25


推荐阅读