This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
I tried below code but it was not working correctly. please help me
<?php
$email = $_POST['email'];
$feedback = $_POST['feedback'];
$to = "balvant1#gmail.com";
$subject = "Mail from HRMSsystem for New Requirement";
$message .= "<b>Email : $email </b>";
$message .= "<b>feedback : $feedback </b>";
$header = "From:xyz#info.com \r\n";
$header = "Cc:balvant#gmail.com \r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html\r\n";
$retval = mail($to,$subject,$message,$hearder);
if( $retval == true )
{echo "Message sent successfully...";}
else{ echo "Message could not be sent..."; }
?>
Thanks in advance.
Three things...
Most hosting companies don't allow you to "bounce" mail off of their servers so unless you own the domain info.com AND you are hosting it on their server, chances are your mail is being blocked.
As #Louis Loudog Trottier said, $retval = mail($to,$subject,$message,$hearder); should be $header not $hearder
You don't necessarily have to have "xyz#info.com" set up. I often use noreply#my-domain-name.tld (which is a non-existent email address) to send mail, BUT you do have to comply with #1.
Also, see the comment by #Svengali as well
Although not a direct answer to your question, using mail() to send your emails is seldom a good idea. Using an email class library is simpler and more straight forward in my opinion.
Please have a look at swiftmailer.org for example.
Related
This question already has answers here:
PHP send mail to multiple email addresses
(13 answers)
Closed 3 years ago.
I am trying to send email to all the members email id's which is stored in the database. Here is the code
<?php
$sql = mysqli_query($con,"select email from email_list where email");
//$recipients = array();
while($row = mysqli_fetch_array($sql,MYSQLI_ASSOC)) {
$recipients[]= $row['email'];
}
$to = $recipients;
$repEmail = 'abc#gmail.com';
$subject = "$title";
$body = "$description";
$headers = 'From: xyz <'.$repEmail.'>'. "\r\n";
$headers .= 'Reply-To: abc#gmail.com' . "\r\n";
$headers .= 'BCC: ' . implode(', ', $recipients) . "\r\n";
if (mail($to, $subject, $body, $headers)){
echo "<script>alert('Email sent')</script>";
}
else {
echo "<script>alert('Email failed')</script>";
}
?>
In this above code email goes to 1 person.
When you look at the pho docs : mail() function
to
Receiver, or receivers of the mail. The formatting of this string
must comply with » RFC 2822.
Some examples are:
user#example.com
user#example.com, anotheruser#example.com
User
User , Another User
It clearly states "to" part should be in rfc2822 compliance. You are passing an array which is not acceptable and thus only first value is taken.
Also it's worth mentioning that:
Note: It is worth noting that the mail() function is not suitable for
larger volumes of email in a loop. This function opens and closes an
SMTP socket for each email, which is not very efficient. For the
sending of large amounts of email, see the » PEAR::Mail, and
» PEAR::Mail_Queue packages
.
Thus I'd suggest you to use some mailing library such as phpMailer or swiftmailer for better functionality or better use mail queue.
Your $to should be $to = "address#one.com, address#two.com, address#three.com"
So add
$recipients = array(
"youremailaddress#yourdomain.com",
// more emails here
);
$email_to = implode(',', $recipients); // your email address
add $email_to to your $to.
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 4 years ago.
So I have a normal but long HTML form on this page
The PHP mail script for the form is:-
$to = "something#gmail.com";
$from = $_POST['contact_email'];
$subject = "Application form submission";
$message = "<h2>Tell us what you need?</h2>";
$message .= "Loan Amount Required ?";
$message .= "<br>";
$message .= $_POST['tell_loan_amount'];
$message .= "<br>";
$message .= "<br>";
$message .= "What For?";
$message .= "<br>";
$message .= $_POST['tell_what_for'];
/* and so on */
$headers = "From: $from" . "\r\n" ;
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset: utf8\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion();
if( mail($to,$subject,$message,$headers)) {
echo "<h1>Thank you for the Application</h1>";
echo "<p>We will now review the application. This process normally takes 2-3 Business Hours. If we need to discuss any aspect of the application we will contact you. If you have any questions at all please do not hesitate to contact us on <strong>1300 815 462</strong></p>";
}
else {
echo "failed";
}
Now the problem is that mail only gets sent sometimes. I have had several clients contact and said that they successfully reached the thank you page and received the success message but we never received the mail. And yes, not in Spam either.
Is it happening because it is set to gmail?
Or is it happening because of incorrect encoding? (Our clients are filling form in English.)
Or do I need to use mb_send_mail() instead of mail() and remove the encoding code altogether?
use this command on you server it will output what happen to your sent mail :
tail -f /var/log/maillog
sometimes the provider block port 25
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 6 years ago.
Ive been trying this out the whole day but I cant figure out how to send an email from my html contact form containing the information from the form to my email address. Im new to php.
Ive tried running this by uploading it to free web hosting. I get the message "success!" when I press the submit button on my html form but no email is actually sent.
Any help is appreciated.
PHP script:
<?php
//Subject
$subject ="Contact Form Submission";
// Name
$name =$_POST['InputName'];
// Message
$message =$_POST['InputMessage'];
//Mail of Sender
$email =$_POST['InputEmail'];
//From
$header = "From:$name<$email>";
$send_contact=mail("myemail#gmail.com",$subject,$message,$header);
//Check if mail was sent
if($send_contact){
echo "Success!";
}
else {
echo "Error!";
}
?>
EDIT: Figured it out after one whole day of trial and error. The problem was with the free web host I was using. Changed hosts and the code started working fine. Hope this helps someone in the future. Thanks all for the help.
I have a pretty good idea why your code is not working. It happened to me a long time ago. The reason why your code is not working is because :
When you pass "from" in headers, php expects an existing email account of your
server. For example : $headers = 'From: emailacc#yourserver.com';
So first thing you gotta do is create an email account on your server. And then put the From in header to the email address that you've just created.
The From field in the $headers is not the From as you think.
<?php
$email = $_POST["InputEmail"];
$subject = $_POST["InputSubject"];
$message = "From: ".$email.", ".$_POST["InputMessage"]; // you put the email address from the input form here
$headers = 'From: emailacc#yourserver.com'; // here is the email address specified from which u want to send the email.(i.e. your server email address)
mail($to, $subject, $message, $headers)
?>
I'm sure this will do the job :)
Have a shot at this.
I changed you're $header variable around a little bit, so that rather than setting the email as "$email", It'll actually pass through the posted email entered in the form. This apply's to the name too.
I also made it so that you pass the mail function through the parameters of the if statement, rather than setting a new variable.
$headers = "From: " . $name . "<" . $email . ">"; // notice new concatenation
if(mail("myemail#gmail.com", "Contact Form Submission", $message, $headers)){
// success message
} else {
// error message
}
Really hope this helps! :)
Try adding spaces after the "=" that might be the problem,
If that doesn't work you could try to use this
<?php
$emailvariable = $_POST['InputEmail']
$to = 'example#gmail.com';
$subject = "Form"
$message = $_POST['InputMessage'];
$headers = "From: $emailvariable";
mail($to, $subject, $message, $headers);
?>
Hope this helps
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 6 years ago.
I'm trying to learn a bit of basics of PHP, but as always I start from living examples like mailing. I'm not sure my tutorial was prepared good or I just made a couple of silly mistakes. There may be a problem with " ' because I haven't figured out which one should be where :) So, my mail is not sending an email, and definitely it's not going to spam so I believe I screw up ' and " part. Thanks for help!
$name = $_POST['nick'];
$visitor_email = $_POST['email'];
$visitor_tel = $_POST['tel'];
$message = $_POST['msg'];
$email_from = 'mail#mail.pl';
$email_subject = "Nowe zlecenie: ";
$email_body = "Nowe zlecenie od $name.\n".
"Email kontaktowy: $visitor_email".
"Telefon kontaktowy: $visitor_tel".
"Zlecenie: $message".
$to = 'mail#mail.pl';
$headers = "Od: $email_from \r\n";
mail($to,$email_subject,$email_body,$headers);
For debugging do like below:
if(mail($to,$email_subject,$email_body,$headers))
echo "mail sent";
else
echo "not send";
This question already has answers here:
How to avoid my mails sent from PHP mail() being marked as spam?
(2 answers)
php mail function: legitimate mails marked as spam by gmail and hotmail
(2 answers)
Closed 8 years ago.
i have used mail() , when i tried with "test" as subject mails are going fine to the inbox but when i change the subject line to 6 or 7 words mails are going to spam . Please can any one help me out . because my subject will be keep on changing so i need a permanent solution even after i change the subject line .
i have tried to put the sender in $header and i checked with mime type still it does not work
require_once("mailer.php");
if(isset($_POST['to']) && !empty($_POST['to']) && isset($_POST['subject']) && !empty($_POST['subject']) && isset($_POST['from'])
&& !empty($_POST['from'])){
$receieverEmailIdArray = explode(',',$_POST['to']);
$from= $_POST['from'];
$subject= $_POST['subject'];
}
else {
echo "Fill all the fields.";
die();
}
$smtptype= 'godaddy';
$content= "<html>
</html>"
Thanks,
Raghu
You can add the Detailed headers Code below.
$headers = "From: Example#site.com\r\n";
$headers .= "Reply-To: Example#site.com\r\n";
$headers .= "Return-Path: Example#site.com\r\n";
$headers .= "CC: Example#site.com\r\n";
if ( mail($to,$subject,$message,$headers) )
{
echo "The email has been Successfully sent!";
}
else
{
echo "Email Sending Failed";
}
?>
Refer this Site this has some useful Information Click Here!!!