1

This is my sendemail.php. It is not working. Are there any mistakes on it ?

<?php
    $name       = @trim(stripslashes($_POST['name'])); 
    $from       = @trim(stripslashes($_POST['email'])); 
    $subject    = @trim(stripslashes($_POST['subject'])); 
    $message    = @trim(stripslashes($_POST['message'])); 
    $to         = 'richardhenokh@gmail.com';//replace with your email

    $headers   = array();
    $headers[] = "MIME-Version: 1.0";
    $headers[] = "Content-type: text/plain; charset=iso-8859-1";
    $headers[] = "From: {$name} <{$from}>";
    $headers[] = "Reply-To: <{$from}>";
    $headers[] = "Subject: {$subject}";
    $headers[] = "X-Mailer: PHP/".phpversion();

    mail($to, $subject, $message, $headers);

    die;
Arslan Ali
  • 16,978
  • 8
  • 56
  • 70

1 Answers1

0

try this. It is working fine

<?php
$name       = @trim(stripslashes($_POST['name'])); 
$from       = @trim(stripslashes($_POST['email'])); 
$subject    = @trim(stripslashes($_POST['subject'])); 
$message    = @trim(stripslashes($_POST['message'])); 
$to         = 'imaphpdeveloper@gmail.com';//replace with your email


$headers = "MIME-Version: 1.0";
$headers .= "Content-type: text/plain; charset=iso-8859-1";
$headers .= "From: {$name} <{$from}>";
$headers .= "Reply-To: <{$from}>";
$headers .= "Subject: {$subject}";
$headers .= "X-Mailer: PHP/".phpversion();

mail($to, $subject, $message, $headers);

die;

?>

Also you can try PHPmailer. headers should be a string not an array. Also {$from} etc.. in headers should be replaced properly. Now using above code mail is sending. But have to replace {$from} properly.

Butterfly
  • 2,418
  • 5
  • 30
  • 49