Qustion about "contact us" page [closed] - php

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
The following is the code for "Contact Us" page. Is this wrong code?
When I send messages, do not go to my E-mail !
i want The correct way to write it?
<?php
if(isset($_POST['sendmail'])) {
$to='a#example.com';
if (mail($to,$_POST['name'],$_POST['message'])) {
echo 'is ok';
} else {
echo "Error : Not Send Mail";
}
} else {
echo 'not ok!!!';
}
?>

Try this:
http://php.net/manual/en/function.mail.php
<?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);
?>
Customized for your example:
<?php
if(isset($_POST['sendmail'])) {
$to = 'a#outlook.com';
$subject = $_POST['name']; // I do not know if this is your email subject
$message = $_POST['message'];
$headers = 'From: a#outlook.com' . "\r\n" . // This will appear as to who sent the email
'Reply-To: a#outlook.com' . "\r\n" . // This will appear as to who to send the replies
'X-Mailer: PHP/' . phpversion();
if (mail($to, $subject, $message, $headers)) {
echo 'is ok';
} else {
echo "Error : Not Send Mail";
}
} else {
echo 'not ok!!!';
}
?>

Related

Using die() after mail() causes email not to send

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 below?

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.

my php code send empty email [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
Please, this is php code that i used to send from HTML contact page, it works with out error but only i receive empty email! just the object of email i get and nothing else.
<?php
$email_address = $_POST["email"];
$tel_num = $_POST["tel"];
$first_name = $_POST["f_name"];
$last_name = $_POST["l_name"];
$text_send = $_POST["email_text"];
$to_com = "myemal#gmail.com" ;
$subject = " New eMail" ;
mail ($to_com, $subject, $text_send, " From: " . $email_address . $tel_num . $first_name .$last_name );
echo "Your Massage has been sent" ;
?>
So please i need some help?
Please look at this example from php.net
<?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);
?>
the line endings in the header (\r\n) are very important

mail() function doesn't not send infomation to my email [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 8 years ago.
Here is my code:
<?php
header('Content-type: text/plain; charset=utf-8');
$to = 'example#gmail.com';
$subject = 'Message to the site';
$realname = htmlspecialchars($_POST['realname']);
$email = htmlspecialchars($_POST['email']);
$msg = htmlspecialchars($_POST['msg']);
$headers = 'From: example#gmail.com' . "\r\n" .
'Reply-To: example#gmail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $msg, $headers) or die("Error!");
echo 'Thank you! :)';
?>
Could somebody explaing me - why this code does not work properly?
I meant that, when I click button submit, it send the email, but I could not include $msg in it and I don't know why.
Try to add :
$headers .= 'Content-type: text/html';
Add this line under $headers and than check i hope this will work for you...

PHP sending mail

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 .

Categories