This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
Mail sending in php on live server has still not sent mail.
if(isset($_POST['submit'])) {
/*$to = "rahulravalinfo#gmail.com";
$subject = "".$_POST['name']." New Inquiry About
".$_POST['subject'].""; $message = "Contact No.
".$_POST['contact']." Message ".$_POST['message']." Email
".$_POST['message'].""; $header = "From:rahulravalinfo#gmail.com
\r\n"; $retval = mail ($to,$subject,$message,$header); */
$to = "rahulravalinfo#gmail.com"; // this is your Email address
$from = $_POST['name']; // this is the sender's Email address
$first_name = $_POST['name'];
$subject = "New Inquiry from". $_POST['name'];
$message = "Contact ".$_POST['contact'] . $first_name . " wrote the following:" . "\n\n" . $_POST['message'];
$headers = "From:" . $from;
$headers2 = "From:" . $to; $retval = mail($to,$subject,$message,$headers);
if( $retval == true ) {
$i=1; } else {
$i=2; } }
Please ask your server hosting company for the php mail is enable for your selected plan or not.
You can check it using php
if ( function_exists( 'mail' ) )
{
echo 'mail() is available';
}
else
{
echo 'mail() has been disabled';
}
Related
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 3 years ago.
So I've got a script that send a mail from a form on my web page. The user simply put his mail address, the message and his name.
First I send the mail to my contact address. (This is working fine) And after that I send a mail to the user's mail address. (This in not working)
And the last mail function return a success but the user doesn't got a mail.
I tried to log everything and I can't figure out why the mail is probably sent but not received.
The mail is not sending when I have a french accent in the body like "répondons" but it works when it's just "repondons". I don't understand why, but It would be better with accent
<?php
// site owner
$site_name = 'just-request.fr';
$sender_domain = 'contact#just-request.fr';
$to = 'contact#just-request.fr';
// contact form fields
$name = trim( $_POST['name'] );
$email = trim( $_POST['email'] );
$subject = trim( $_POST['subject'] );
$message = trim( $_POST['message'] );
// check for error
$error = false;
if ( $name === "" ) { $error = true; }
if ( $email === "" ) { $error = true; }
if ( $subject === "" ) { $error = true; }
if ( $message === "" ) { $error = true; }
// if no error, then send mail
if ( $error == false )
{
$body = "Name: $name \n\nEmail: $email \n\nMessage: $message";
$headers = "From: " . $site_name . ' <' . $sender_domain . '> ' . "\r\n";
$headers .= "Reply-To: " . $name . ' <' . $email . '> ' . "\r\n";
$mail_result = mail( $to, utf8_decode($subject), utf8_decode($body), $headers );
if ( $mail_result == true )
{
$body = "Bonjour,\n\n";
$body .= "Merci de votre mail, nous le prenons en compte et vous repondrons des que possible.\n\n";
$body .= "Cordialement,\n";
$body .= "L'equipe Request. ";
$subject = "RĂ©ponse automatique";
$new_mail_result = mail( $email, utf8_decode($subject), utf8_decode($body), $headers );
if ( $new_mail_result == true )
{
echo 'success';
}
else
{
echo 'unsuccess';
}
}
else
{
echo 'unsuccess';
}
}
else
{
echo 'error';
}
Try to use mb_send_mail() instead of mail().
Set mb_language() to German/de (ISO-8859-15) or English/en (ISO-8859-1).
Both ISO-8859-15 and ISO-8859-1 include french extra letters.
ISO-8859-15 is ISO-8859-1 after Euro upgrade.
https://www.php.net/manual/en/function.mb-send-mail.php
Sends email. Headers and messages are converted and encoded according to the mb_language() setting. It's a wrapper function for mail(), so see also mail() for details.
Comment: I miss mb_language() option for UTF-8 with quoted-printable encoding.
It would be nice for most (european) "almost ASCII" language specific alphabets.
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 years ago.
I'm trying to create php code for an existing html form. When I try to create the code, it seems to have a problem with the closing parentheses, can anyone help?
<?php
if (isset($_POST['your_name'])) {
$your_name = $_POST['your_name'];
if (isset($_POST['your_email'])) {
$your_email = $_POST['your_email'];
if (isset($_POST['subject'])) ;
$subject = $_POST['subject'];
if (isset($_POST['message'])) ;
$message = $_POST['message'];
$to = "email.co.uk";
$subject = "New Message";
mail ($to, $subject, $message, "From: " . $your_name);
echo "Your message has been sent";
?>
Thanks
This is because you are using ; in every if statement instead of if { .. } statements try this code
<?php
if (isset($_POST['your_name'])) {
$your_name = $_POST['your_name'];
}
if (isset($_POST['your_email'])) {
$your_email = $_POST['your_email'];
}
if (isset($_POST['subject'])) {
$subject = $_POST['subject'];
}
if (isset($_POST['message'])) {
$message = $_POST['message'];
}
$to = "email.co.uk";
$subject = "New Message";
mail ($to, $subject, $message, "From: " . $your_name);
echo "Your message has been sent";
?>
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 6 years ago.
I have searched stack overflow as well as the Ubuntu forums. I am writing a website and I am hosting it myself using a LAMP server. I have a form that a user fills out and want it to send an email once the user clicks the submit button. So far I have tried sendmail, ssmtp, phpmailer, and installing mailutils and using postfix. The reason I believe that it's an issue with the mail program is because after testing I'm getting no errors from the code and I am unable to send mail from the commandline. I would prefer not to use phpmailer as I don't want to hardcode any passwords in the website in the event it gets compromised. I would appreciate any help someone could give me. I have included the mail script if you need config files let me know Thank you in advance.
<?php
session_start();
if(isset($_POST['submit'])){
$to = "jmaggsdf#gmail.com"; // this is your Email address
$from = $_POST['email']; // this is the sender's Email address
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$subject = "Website Email";
$message = $first_name . " " . $last_name . " wrote the following:" . "\n\n" . $_POST['message'];
$type = 'plain'; // or HTML
$charset = 'utf-8';
$_SESSION['from'] = $_POST['email'];
$_SESSION['first_name'] = $_POST['first_name'];
$_SESSION['last_name'] = $_POST['last_name'];
$_SESSION['message'] = $_POST['message'];
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/plain; charset=utf-8' . "\r\n";
$headers .= 'To: ' . $to . '<' . $to . '>' . "\r\n";
$headers .= 'From: ' . $from . '<' . $from . '>' . "\r\n";
if($first_name == NULL || $last_name == NULL || $from == NULL || $message == NULL){
header("Location: mailError.php");
die();
}
else{
//$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
header("Location: thanksPage.php");
//mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
//echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
}
}
?>
It you are sending mail using local host then it will not send mail.
It requires live server.
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 6 years ago.
I have a problem with sending the form to my e-mail.
Currently, when i send the form i get message from "emailtest#test.com" with $message2 but i don't get $message from 'inputEmail' to my e-mail "emailtest#test.com".
I would add that I am not PHP programmer and this is my first script in this language.
I would be very grateful for your help
<?php
$to = 'emailtest#test.com'; // this is your Email address
$from = $_POST['inputEmail']; // this is the sender's Email address
$first_name = $_POST['inputName'];
$inputCompany = $_POST['inputCompany'];
$inputPosition = $_POST['inputPosition'];
$inputProjects = $_POST['inputProjects'];
$inputOfficeProjects = $_POST['inputOfficeProjects'];
$inputPresentation = $_POST['inputPresentation'];
$inputMessage = $_POST['inputMessage'];
$number = $_POST['number'];
$subject = "Test";
$subject2 = "Test1";
$message = $first_name . " example " . $inputPosition . " wrote the following:" . "\n\n" . $_POST['message'];
$message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['message'];
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
// echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
header('Location: dziekujemy.html');
?>
Since your code works in a local environment, with mailtodisk, I suspect a "problem" with the mail server. You are setting the From: Header of the first email send attempt to the email address of the person that filled out the form. Most mail servers might reject that because it is not a valid address that you own. I am not an expert to this so someone might have a better, more detailed explanation.
Remove the headers from the first email or set the From: Header to a address which can actually sent over that mailserver. If this works you can use a Reply-to header which enables most clients to directly answer to the set email address.
Example below:
...
$headers = 'From: ' . $to . "\r\n" .
'Reply-To: '.$from;
...
I might suggest - even it it looks complicated at first - to use PHPMailer. It makes sending emails with PHP much easier.
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 6 years ago.
my code save info in database but doesn't send the message to email and the alert message not work.
can you help me , please ?
`
if(isset($_POST['send'])){
$to = "nada_26_#hotmail.com"; // this is your Email address
$subject = "Form contact";
$subject2 = "Copy of your form submission";
$name = $_POST['name'];
$from = $_POST['email'];
$subject3 = $_POST['subject'];
$company = $_POST['company'];
$content = $_POST['message'];
$message = "Name: ".$name ." Subject: " . $subject3 . " Company: " . $company ."\n\n".$content;
$message2 = "Here is a copy of your message " . "\n\n" . $_POST['message'];
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers); //send the message to the admin
mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
$sql ="INSERT INTO threadnn_arab.contactus VALUES('$name','$from','$subject3','$company','$message','')";
$result=mysql_query($sql);
echo "<script> alert('Mail Sent, Thank you, we will contact you shortly.'); </script>";
header('Location: index.php?#contact');
}
?> `
i think it on your email provider, smtp may be.or you can using PHPMailer look like in this question Send email from Hotmail using php