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.
Related
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.
I am a PHP novice here. I have a send mail script that looks like this:
$to = 'example#email.com';
$from = 'noreply#email.com';
$subject = 'Test Submission';
$message = 'This is just another test.';
$headers = 'From: example#email.com' . "\r\n" .
// 'Reply-To: example#email.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
This script works fine and sends an e-mail when the page is loaded. The problem is that when I alter the script just enough so that the form is not submitted until the Submit button is clicked then all of a sudden nothing works anymore. Here is the altered code I have been trying to use (and which seems to go right along with what the PHP site suggests):
if(isset($_POST['submit'])){
$to = 'example#email.com';
$from = 'noreply#email.com';
$subject = 'Test Submission';
$message = 'This is just another test.';
$headers = 'From: example#email.com' . "\r\n" .
// 'Reply-To: example#email.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
}
Make sure your submit button on your form has a NAME attribute. The value of that NAME attribute is what gets sent to the server, so:
<input type="submit" name="btnSubmit" value="Go!">
...would result in this variable and value:
$_POST["btnSubmit"] = "Go!";
...and you would check it like this:
if(isset($_POST["btnSubmit"]))
{
...
}
I've made a website with a mailing form, and the php to send it is as follows:
<?php
$to = "example#outlook.com";
$subject = $_POST["subject"];
$message = $_POST["message"];
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
It won't send anything.
Can anyone tell what's wrong in the script?
If it helps on anything, I'm trying to send to an Outlook email.
Thanks
I have a script that sends an email, but instead of the sender name being "admin#foo.bar", I want it to say "Foobar Admin". How can I do this?
Thanks!
Do you want something like this??
$email_from = $full_name.'<'.$email_from.'>';
try this
<?php
$to = 'nobody#example.com';
$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);
?>
for reference use http://www.php.net/manual/en/function.mail.php
Use this;
<?php
$to = 'to#mail.com';
$subject = 'Your subject';
$message = 'Your message';
$headers = 'From: Foobar Admin<admin#foo.bar>' . "\r\n" .
'Reply-To: admin#foo.bar' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
mail("recipient#aol.com","subject","message","From:Foobar Admin<foobar#admin.com>");
here is my code....
$subject = "This is Subject";
$headers .= 'Content-type: text/html; charset=iso-8859-1';
$to = 'foo#foo.com';
$body = 'Mail Content Here';
mail($to, $subject, $body, $headers);
but when i open this file it sends a mail to $to successfully but with wrong headers....and my hosting server default address i.e mars.myhosting.com, instead of mydomain#domain.com how can i fix that
Look at this from php.net
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: Webmaster <webmaster#example.com>' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
Add the from header
Here is what I would do via PHP:
<?PHP
$to = 'email#address.com';
$subject = 'desired subject';
$message = 'desired message';
$headers = 'From: example#email.com' . "\r\n" .
'Reply-To: example#email.com' . "\r\n" .
'Return-Path: example#email.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
I hope that helps some :)