On my server I am trying to send an email via PHP but it always just says message not set, even after hardcoding in values and removing the header it still says message not sent. What could the problem be?
<?php
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);
$recipient = $_POST["recipient"];
$title = $_POST["title"];
$body = $_POST["body"];
$headers = 'From: admin#example.com' . "\r\n" .
'Reply-To: admin#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$sendMail = mail($recipient, $title, $body, $headers);
if( $sendMail == true )
{
echo "Message sent successfully...";
}
else
{
echo "Message could not be sent...";
}
?>
I dont see problem with the code. Mostly because your mail server is not configured .
Related
I have the code below and the redirect works. However when I have the die() command at the bottom the email doesn't get sent. The email goes fine without the die() command.
Is there a way I can stop the php script continuing without stopping the email from working?
$to = 'hello#nospam.com';
$subject = "Test Subject";
$message = "Test Message";
$headers = 'From: robocop#nospam.com' . "\r\n" .
'Reply-To: robocop#nosopam.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
header('Location:http://nospam.com/home/bouncer.php');
die();
Try this for testing. I don't think that there are really such problem.
$to = 'hello#nospam.com';
$subject = "Test Subject";
$message = "Test Message";
$headers = 'From: robocop#nospam.com' . "\r\n" .
'Reply-To: robocop#nosopam.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
if (mail($to, $subject, $message, $headers)) {
header('Location:http://nospam.com/home/bouncer.php');
} else {
echo "Fail";
}
die(); // and use for also exit(); for testing
That's very interesting if it is real problem.
What is wrong with my PHP Send Mail function? I am hosting this script on a live server.
$to = 'myemail#gmail.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: exampleemail#gmail.com' . "\r\n" .
'Reply-To: exampleemail#gmail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
if(mail($to, $subject, $message, $headers)){}
else{
echo "Email sending failed";
}
I keep receiving the "Email sending Failed" message.
The issue I am having is in the message portion of the email. The email sends just fine, the outline is there but no name email or message is printed from the variable. I can't seem to see what the issue is. Any help is appreciated.
<?php session_start();
$name=$_POST['name'];
$email=$_POST['email'];
$text=$_POST['text'];
$to= 'noreply#noreply.com';
$subject = 'Request';
$message='Hello, my name is:' . $name . "\r\n" . 'My Email is: ' . $email . "\r\n" . 'My Message is: '. $text;
$headers = 'From: Request' . "\r\n" .
'Reply-To: noreply#noreply.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
echo 'Mail Sent';
?>
From the comment you are passing the data as query string not as payload in the POST. SO change
$name=$_POST['name'];
$email=$_POST['email'];
$text=$_POST['text'];
to
$name=$_GET['name'];
$email=$_GET['email'];
$text=$_GET['text'];
And should work !
You sent form using GET method, data are in $_GET:
<?php
session_start();
$name = $_GET['name']; // here
$email = $_GET['email']; // here
$text = $_GET['text']; // here
$to = 'noreply#noreply.com';
$subject = 'Request';
$message='Hello, my name is:' . $name . "\r\n" . 'My Email is: ' . $email . "\r\n" . 'My Message is: '. $text;
$headers = 'From: Request' . "\r\n" .
'Reply-To: noreply#noreply.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
echo 'Mail Sent';
?>
To use your current script version, just change method attribute in form to post, like <form method=post ...>
I'm sending an email using php's mail() function. My code is as following:
$to = email#email.com;
$subject = "Subject of email";
ob_start();
echo include('emailcontent.php');
$message = ob_get_contents();
ob_end_clean();
$headers =
'From: Email <email#email.com>' . "\r\n" .
'Reply-To: Email <no-reply#email.com>' . "\r\n" .
"Content-type:text/html;charset=UTF-8" . "\r\n" .
"MIME-Version: 1.0" . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
For some reason the string "1" is added at the end of the message. This happens in the include('emailcontent.php'), because if I add another string to the message after the include the "1" is added before that addition.
In the emailcontent.php is no 1 or whatsoever.
echo include('emailcontent.php');
Remove the echo. That echo puts 1 in there
You might ask why does echo put 1 in there when its not added anywhere? Because when your file is successfully included the return value of that include is TRUE and when you send that to echo it prints 1. Try
echo 2==2; //1
Why you are echoing the php page? You have to include the page like,
include('emailcontent.php');
Remove the echo it is causing the 1.
<?php
$to = 'something#gmail.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: example#test.com' . "\r\n" .
'Reply-To: example#test.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
$send = mail($to, $subject, $message, $headers );
if ($send)
$mailReturns = "Mail sent successfully.";
else
$mailReturns = "Mail sent failed.";
?>
<?php echo $mailReturns; ?>
after run it shows mail sent successfully
but mail not showing up in any of the accounts. iv tried gmail, yahoo, rediff and ibibo why????
If you have qmail installed on your server, try using that. Alternatively, there is a nice PHP mailer class called swiftmail that is available here: http://swiftmailer.org/ you can try.
Your emails are probably being junked/marked as spam.
Try to see in spam folder.