I just need that when form is submitted mail is send to recipient. My form submitted with Response code of 200k but mail is not Delivered. I have installed sendmail.
sendmail.php code:
if(isset($_POST['submit']))
{
$subject = $_POST['subject'];
$to = "abc#gmail.com";
$from = $_POST['email'];
//data
$msg = "NAME: " .$_POST['name'] ."<br>\n";
$msg .= "EMAIL: " .$_POST['email'] ."<br>\n";
$msg .= "WEBSITE: " .$_POST['web'] ."<br>\n";
$msg .= "COMMENTS: " .$_POST['comments'] ."<br>\n";
//Headers
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=UTF-8\r\n";
$headers .= "From: <".$from. ">" ;
mail ($to, $subject,$msg, $headers);
echo "sent";
}
installed mail server in php.ini file:
[mail function]
; Setup for Linux systems
sendmail_path = /usr/sbin/sendmail -t
sendmail_from = me#myserver.com
mail ($to, $subject,$msg, $headers);
echo "sent";
instead of this ,first check if the mail is sent
$mail=mail ($to, $subject,$msg, $headers);
if($mail){
echo "sent";
}else{
echo "failed.";
}
By this actually u can know whether your mail function in working or not
if it is not working.the problem can be with SMTP settings in your localhost
enable errors in php if not enabled using
ini_set('display_errors',1);
Have you checked mail settings in you php.ini ?
PHP Runtime Configuration
If you don't have access to the PHP settings you can use PHP Mailer to deliver emails with your own parameters
Related
I am trying to send email from localhost XAMPP, I have updated all the required files but still unable to send Email from localhost.
Regards: M.Tahseen ur Rehman.
php.ini
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
sendmail.ini
auth_username=myemail#gmail.com
auth_password=mypassword
After all these update i have created a PHP file mail.php to send mails but its not delivering any Email.
include 'connect.php';
$subject = $_REQUEST['subject'] ; // Subject of your email
$personal_email= "abc#hotmail.com";
$message .= 'Name: ' . $_REQUEST['name'] . "<br>";
$message .= $_REQUEST['product_type']. "<br>";
$message .= $_REQUEST['message'];
$subject_to_sender= "Confirmation";
$message_to_sender = "Thanks for contacting us";
$name= $_REQUEST['name'];
$email= $_REQUEST['email'];
$message= $_REQUEST['message'];
$product_type= $_REQUEST['product_type'];
$address= $_REQUEST['address'];
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= "From: " . $_REQUEST['email'] . "\r\n"; // Sender's E-mail
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
if (#mail($email, $subject_to_sender, $message_to_sender, $headers))
{
mail($personal_email, $subject, $message, $headers);
// Transfer the value 'sent' to ajax function for showing success message.
echo 'sent';
}
On Send Button i also send all the Data into Database, and its successfully inserting data into database.
Kindly guide me.
php mail return false when i run mail function
here is my code
$to = 'xxxxxx#gmail.com';
$subject = 'Login';
$message = 'Thanks for Login ! Your account has been logged on website.';
$headers = 'From:xxxxx#gmail.com' . "\r\n";
var_dump(mail($to, $subject, $message, $headers));
when i opened mail log there is no error found and when i test to send mail over ubuntu terminal using this command
echo "Test mail from postfix" | mail -s "Test Postfix" you#example.com
it sends to me mail correctly
also i configured php.ini
sendmail_path = /usr/sbin/sendmail -t -i -f care#mydomain.com
first try this one: use this code make a Connection
<html>
<head>
<title>Sending HTML email using PHP</title>
</head>
<body>
<?php
$to = "xyz#somedomain.com";
$subject = "This is subject";
$message = "<b>This is HTML message.</b>";
$message .= "<h1>This is headline.</h1>";
$header = "From:abc#somedomain.com \r\n";
$header .= "Cc:afgh#somedomain.com \r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html\r\n";
$retval = mail ($to,$subject,$message,$header);
if( $retval == true ) {
echo "Message sent successfully...";
}else {
echo "Message could not be sent...";
}
?>
</body>
</html>
I had this issue, but in my case it was due to my postfix configuration being quite restrictive. I found this error in /var/log/maillog:
postfix/sendmail[pid]: fatal: User apache(id) is not allowed to submit mail
The fix was to add "apache" to the main.cf:
authorized_submit_users = root spamd apache
Then, don't forget to restart postfix
systemctl restart postfix
I have a problem with my mail in php. I code form to send email. I receive email on gmail but I have other mail address and I can't get email on it.
I checked in spam and there is no email also.
Below is my code.
<?php
$emailErr = "";
$endMessage = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["email"])) {
$emailErr = "Proszę uzupełnić pole e-mail";
}
else if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
//send email
$namesurname = $_REQUEST['name_surname'] ;
$email = $_REQUEST['email'] ;
$number = $_REQUEST['number'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
$message = $subject . ": " . $message . " " . $number . " " . $namesurname . " " . $email;
$subject = "=?UTF-8?B?".base64_encode($subject)."?=";
mail("szafor#szafor.pl", "Zamówienie pomiaru",
$message, "From: formularz#szafortest.pl \r\n"."Content-Type: text/plain; charset=UTF-8\r\n");
$endMessage = "Dziękuję za przesłanie wiadomości.";
}
}
?>
One important thing to consider with sending mail is that you should at least have the return path of the message be an email address that is actually hosted on the server that you are sending from.
You can set the From and the Reply-To address as any address, but the return-path should be set to a valid email address hosted on your server. Let's say that you want the "reply" button to send back to "this_email#wherever.com" but the server you are using hosts email for "mydomain.com". Create an email account on your server, "info#mydomain.com" for example.
$recipient = "sendto#email.com";
$subject = "Test email";
$message = "This is the message.";
$headers .= "From: Your Name Here <any_email#wherever.com>\n\r";
$headers .= "Reply-To: Your Name Here <any_email#wherever.com>\n\r";
$headers .= "Return-Path: Your Name Here <info#mydomain.com>\n\r";
$headers .= "Content-Type: text/plain; charset=UTF-8\r\n";
$headers .="X-Mailer: PHP/" . phpversion() . "\r\n";
$headers .="MIME-Version: 1.0\r\n";
mail($recipient, $subject, $message, $headers);
I have found that the more valid header information that I provide, the more likely the email will be delivered. Right now these headers always work for me, and I have a scheduling program that is sending email to a hundred different email addresses every day. See if that works better for you.
I tried to send an email vie PHP but got nothing. I don't see what I am doing wrong.
// Send an email.
$subject = 'Welcome to mypage';
$message = 'your registration went fine.';
echo $email;
$a=mail($email, $subject, $message );
echo 'Mail sent, a='.$a;
I checked that $email contains my email address and $a = 1 after running the code. Still my mailbox is empty. Why?
You probably don't have Apache configured correctly. That's why the email isn't sending.
Some mail servers require mail headers:
$header = "MIME-Version 1.0\r\n";
$header .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$header .= "From: ".$sendername." <".$fromemail.">\r\n";
$header .= "X-Mailer: PHP/".phpversion();
mail($email, $subject, $message, $header);
<?php
$sendto = "account#gmail.com";
$subject = "email confirmation"; // Subject
$message = "the body of the email - this email is to confirm etc...";
# send the email
mail($sendto, $subject, $message);
?>
this is the code that i wrote to test mail function on localhost.
i have ran the script in browser for several times and still dun receive any email in my mail box.
Do I need any additional configurations?
thx in advance!
Basically is hard to send a mail from localhost to any mail providers.
They have big restrictions on the incoming mails, and the simply mail() won't work.
You need to use an SMTP server.
and define that server in php configuration
smtp = localhost #(here should be your smtp server)
smtp_port = 25
if you don't have an SMTP server, try to pass all headers like in PHP examples:
$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);
http://www.php.net/manual/en/function.mail.php
You need to make sure that you have your PHP installation set up to use a working SMTP Server. You might find what you're looking for in answers to this question. Failing that you'll likely need to test your script on your live web server.
<?php
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
?>
<?php
$email_from = 'yourname#yourwebsite.com';
$email_subject = "New Form submission";
$email_body = "You have received a new message from the user $name.\n".
"Here is the message:\n $message"
?>
<?php
$to = "inspiretechpark#gmail.com";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
mail($to,$email_subject,$email_body,$headers);
?>
<?php
$to = "name1#website-name.com, name2#website-name.com,name3#website-
name.com";
mail($to,$email_subject,$email_body,$headers);
?>
<?php
$to = "name1#website-name.com, name2#website-name.com,name3#website-
name.com";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
$headers .= "Cc: someone#domain.com \r\n";
$headers .= "Bcc: someoneelse#domain.com \r\n";
mail($to,$email_subject,$email_body,$headers);
?>
Try This Guys..This Is For Sending Mail
Try this:
<?php
$sender = 'email#example.com';
$recipient = 'email#example.com';
$subject = "php mail test";
$message = "php test message";
$headers = 'From:' . $sender;
if (mail($recipient, $subject, $message, $headers))
{
echo "Message accepted";
}
else
{
echo "Error: Message not accepted";
}
?>
If you are working with localhost then, i hope it will never work. It will work only on a mail configured server. Please try on it.