0
<?php
 $path = 'data.txt';
 if (isset($_POST['email']) ) {
    $fh = fopen($path,"a+");
    $string = $_POST['email'].' - '.$_POST['field2'];
    fwrite($fh,$string); // Write information to the file
    fclose($fh); // Close the file
 }
 
 
 
 

$to = $_POST['email'];
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
    'Reply-To: webmaster@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

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

?>

Can someone tell me what is wrong with this code? I want that the script to send email to $_POST['email'] that came from a previous html file. So first,store that email,and after that sent an email to it. Thank you

Edit: The script store the email with success but the email is not sent. Thanks again

  • 4
    Does this answer your question? [PHP mail function doesn't complete sending of e-mail](https://stackoverflow.com/questions/24644436/php-mail-function-doesnt-complete-sending-of-e-mail) – M. Eriksson Sep 01 '20 at 09:15
  • 1
    _“I want that the script to send email to $_POST['email']”_ - do you _really_ want that? Because that is how you create scripts that will get abused by spammers, to use _your_ system to send emails to arbitrary recipients of their choice. – CBroe Sep 01 '20 at 10:07
  • What do you see in the error log? – Lajos Arpad Sep 02 '20 at 20:59

0 Answers0