简体   繁体   中英

PHP script not sending/receiving email

I have a site with a form that is suppose to send an email to my company and another to the user that filled out the form. I have loaded the site with all of the additional files to the server, but when I fill out the form to test it an error pops up saying "Not Found". I am using the GET method of PHP to handle it. I am new to PHP, and Web design in general. Thank you.

<?php
//Function that sends the email to the person who submitted the form
function send_email(){
//This sends an email to the person who submitted the form
// email fields: to, from, subject. Put your values here!
$sendermail = 'company@email.com';
$from = "Company<".$sendermail.">";
$to = $_GET['email'];
$subject = 'Product Information';
$message = "A member of our sales team will be getting back to you shortly.  Thank you for your interest in our great line of products."."\n\n"."Best Regards,"."\n\n"."The Team";
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/plain; charset=iso-8859-1' . "\n";
$headers .= 'From: '. $from . "\r\n" .
'Reply-To: '. $sendermail. "\r\n" .
'X-Mailer: PHP/' . phpversion();

$ok = @mail($to, $subject, $message, $headers);

//This sends the contents of the form submission to the website owner
$sendermail2 = $_GET['email'];
$from2 = $_GET['first-name'].' '.$_GET['last-name'].' <'.$sendermail2.'>';
$to2 = 'company@email.com';
$subject2 = 'A customer submission from the product page';
$message2 = "Name: ". $_GET['first-name'] ." ". $_GET['last-name'] ."\n\n". "Company: ". $_GET['company'] ."\n\n". "Email: ". $_GET['first-name'] ."\n\n". "Interest: ".$_GET['Interest'];
$headers2  = 'MIME-Version: 1.0' . "\r\n";
$headers2 .= 'Content-type: text/plain; charset=iso-8859-1' . "\n";
$headers2 .= 'From: '. $from2 . "\r\n" .
'Reply-To: '. $sendermail2. "\r\n" .
'X-Mailer: PHP/' . phpversion();

$ok2 = @mail($to2, $subject2, $message2, $headers2);
}
return send_email();
?>

...and this code is in the body of the HTML page.

<FORM ACTION="http://www.server.com/html/form_process.php" METHOD=GET>

Solution for your Red Hat Server:

sudo yum install postfix

Subsequently:

sudo echo "sendmail_from = me@example.com" >> /your/directory/php.ini

And finally:

sudo echo "sendmail_path = /usr/sbin/sendmail -t -i -f me@example.com" >> /your/directory/php.ini

Replace /your/directory/php.ini with your real php.ini directory and me@example.com with the email address you want and restart apache, php and postfix, or directly the server.

A not found error usually means that you are sending the form to the wrong URL. Check the Url you are sending to and the path to the php file to see if they are correct

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM