问题
Ive got the following php code:
<?
if ($_POST['emailme']) {
$yemail = $_POST['email'];
$host = $_SERVER['HTTP_HOST'];
$email = "<autoreply@$host>";
if (mail('$yemail', 'This is a Subject', 'This is the body of the email', 'From: $email')) {
echo "Message sent!";
} else {
echo "Message failed sending!";
}
}
?>
This is my HTML:
<FORM METHOD="POST" ACTION=""><INPUT TYPE='TEXT' CLASS='BOX' NAME='email' /><INPUT TYPE='SUBMIT' NAME='emailme' CLASS='SUBMITBOX' VALUE='Send!' /></FORM>
Any ideas why its not sending the email ? it says Message Sent but im not receiving any emails in my inbox
All help is much appreciated, thanks
PS: ive tried the following (with double quotes):
if (mail("$yemail", "This is a Subject", "This is the body of the email", "From:" . $email)) {
echo "Message sent!";
} else {
echo "Message failed sending!";
}
but still no luck
回答1:
try this
if (mail('akh40@hotmail.co.uk', 'This is a Subject', 'This is the body of the email', 'From:'. $email))
回答2:
Apparently most hosting companies are dropping support for php's mail() function in favour of SMTP versions of email scripts.
See http://www.thesitewizard.com/php/protect-script-from-email-injection.shtml for an explanation of why.
Try this for an SMTP/SSL script:
<?php
require_once "Mail.php";
$from = "Sandra Sender <sender@example.com>";
$to = "Ramona Recipient <recipient@example.com>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$host = "ssl://mail.example.com";
$port = "465";
$username = "smtp_username";
$password = "smtp_password";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
?>
来源:https://stackoverflow.com/questions/23045613/my-php-mail-function-is-not-working