I realize that this is similar to this question, however, I only get a double email when sending to myself. I have sent emails to others with the same script, and they get a single email. This is the email script:
<?php
function sendEmail( $recipient, $sub, $msg )
{
$to = $recipient;
$subject = $sub;
$message = $msg;
mail( $to, $subject, $message );
}
?>
The code calling this is this:
if( $retVal != FALSE ) // No errors in execution of report generation
{
$subject = "Successful Report";
$message = "The report was successfully generated.";
// Notify people about success
sendEmail( $mailto, $subject, $message );
echo "Successful report generation\n";
}
else // Error in report generation
{
$subject = "Unsuccessful Report";
$message = "The report failed to generate.";
// Notify people about failure
sendEmail( $mailto, $subject, $message );
echo "Report generation was unsuccessful\n";
}
where $retval is the return value of system(). Can anyone shed some light on this issue? Or is this something that can be overlooked?
Thanks very much
-rusty
Based on the conversation: You are the only recipient that is receiving double email, and the string "Successful report generation" only prints once. It sounds like PHP is not the culprit here, rather something outside of PHP, such as the MTA.
Take a look at the headers of the two email you receive, particularly the MessageID header. If they are identical, then a single email was sent from PHP (good!) and somewhere along the line it got delivered to you twice.
If they are not identical (messy), then PHP did in fact send out two emails (not likely) or there is a resender somewhere between PHP and your mail client.
In the later case, I would take a deeper look at the headers in your email, to determine the source and route of each email, as well as the envelope to determine where the MTA though it was sending mail to.
I would add the output from debug_backtrace() into the body of your email. This will allow you to determine when the sendEmail function is called and who called it.
$message = "";
$header = "Content-Type: text/html; charset=UTF-8;\r\n";
mail($mailto, $subject, $message, $header);
Related
I have a simple function that uses wp_mail, like:
$headers = "From: $myName <$myEmail>" . "\r\n";
wp_mail( $myToEmail, $mySubject, $myMessage, $myHeaders );
When I put this code onto a site, it seems there are sometimes when the email does not send, but I do not see any way to replicate the issue and it generally works.
Where are potential points of failure?
Is it possible the email is failing on the server side occasionally?
You need to use WP_mail() function to your contact form.You can use this way
see this is example:
headers = "From: $myName <$myEmail>" . "\r\n";
//Here put your Validation and send mail
$sent = wp_mail( $myToEmail, $mySubject, $myMessage, $myHeaders );
if($sent) {
}//message sent!
else {
}//message wasn't sent
I have a few questions regarding sending email in PHP. I've been on google for the last few days and I'm still having trouble getting this to fully work.
My first question is how do I change the "From" section of my email? I have "To: support#mydomain.com" in my "from" section:
I'd like to have just the proper name of my domain (eg: "testingstuff.com" -> "Testing Stuff"). How could I achieve this?
Once I actually open the email everything in it is fine and correct, including the From email address being "support#mydomain.com".
Also my mail won't send to gmail addresses. It shows up in my mail queue and my logs say it is sent but it never is received on my gmail. Do I have to take extra steps for Google to accept my email? If so what are those? Do other major mail provides require the same steps, or are they different steps?
This is my code so far:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
ini_set("sendmail_from", "support#mydomain.com");
class email {
public static function send($to, $subject, $message) {
$headers = "From: Testing Stuff <support#mydomaincom>\r\n";
$headers .= "Reply-To: support#mydomain.com\r\n";
$headers .= "Content-type: text/html\r\n";
mail($to, $subject, $message, $headers);
}
}
?>
Usage:
require_once("../mail.php");
email::send("support#mydomaincom", "testing email subject", "testing email body");
Am I doing anything wrong in my code?
You need to check if the email is sent properly checking the mail() result, in this way:
$result = mail($to, $subject, $message, $headers);
if(!$result) {
echo "Error";
} else {
echo "Success";
}
this is inside your static function,
Also check your spam folder if the mail function return "success".
I have some php here that works great. I want a mail to be sent to the user who submits a form and I also want a copy of that mail sent to myself but I don't want my email address to be made available to the user.
Here's the php I'm using to govern the mail sending ...
$to = 'xxxx#xxxx.com' . ', ';
$to .= $email;
$subject = 'xxxx';
$message = "Thank you for submitting the form.";
$headers = "From: xxxx#xxxx.com\r\nReply-To: xxxx#xxxx.com";
$mail_sent = #mail( $to, $subject, $message, $headers );
echo $mail_sent ? "Mail sent" : "Mail failed";
When the code is parsed emails are duly sent to both the users submitted email ($email) and the address I enter in the first $to variable however the user can see the email address I enter as another recipient when they receive the email. Anyone know how I can get around this? Any help will be much appreciated. Thanks.
Use a BCC header instead of an additional To in your $headers string. It stands for "Blind Carbon Copy", and instructs the mail server to duplicate the mail to extra recipients, but remove that header from the original copy, so the main recipients can't know it was there.
I am hosting my web application(pnpmkt.com) from GODADDY.com they have given me some email account like info#pnpmkt.com. I want to send welcome message to new user's to their mail account in other mail servers like google, yahoo.for example, my mail function is-
<?php
$address = "piysuh#gmail.com";
$Subject = "PNP Solutions";
$body = "Welcome to PNP";
$mailsend = mail("$address", "$Subject", "$body.");
print("$mailsend");
?>
what other configurations are required?Any path name or server name??
Here is a wrapper function I use to send emails (text or html):
// $Sender: Sender email
// $Recipient: Recipient email
// $Subject: Email subject
// $Detail: Plain text or HTML (should include <html> and <body> tags)
// $Type: TEXT or HTML
function sendmail( $Sender, $Recipient, $Subject, $Detail, $Type )
{
switch ( $Type )
{
case "TEXT":
$Header = "From: $Sender\n";
break;
case "HTML":
$Header = "From: $Sender\n";
$Header .= "MIME-Version: 1.0\n";
$Header .= "Content-type: text/html; charset=iso-8859-1\n";
break;
}
return mail( $Recipient, $Subject, $Detail, $Header );
}
Can you clarify whether you are having trouble sending emails using this method? From what I can see, your code is good, and should operate without any problems.
I just tested this code, myself, and it works fine.
It should be noted that the mail() function returns TRUE on success and FALSE on failure so echoing that is not a terribly useful thing to do. (You'll just get "1" if it worked and "0" if it didn't.)
If you are wanting to include more advanced features and facilities in your emails, however, you may want to look at PHPmailer, which is a PHP Class allowing for the sending of HTML Emails, changing various settings like the Sender's email address and name, etc.
I have successfully sent mail using PHP's mail() function before, and for my password reset notification e-mail, I copied the syntax I was using elsewhere, but I guess I messed it up, as it's not arriving at its destination. Here is the code I'm using:
$headers = 'To:'.$email."\r\n";
$headers .= 'From: webmaster#aromaclear.co.uk'."\r\n";
$to = $email."\r\n";
$subject = 'AromaClear Password Reset Notification'. "\r\n";
$msg = 'From: AromaClear'."\r\n";
$msg .='Subject: Your New Password'. "\r\n";
$msg .= 'Message: Your new password is '.$newpass."\r\n";
$msg.= 'If you have received this e-mail in error, please ignore it.'. "\r\n";
mail($to, $subject, $msg, $headers);
Any thoughts?
Try looking at your server's mail logs to see why it isn't getting forwarded. Ex., it may be that this server's sendmail wants the -f flag for the From header instead of specifying it in the header text.
mail($to, $subject, $msg, $headers, "-f $from");
Also, you seem to be doing a lot of extra/weird work. This is a lot easier:
$subject = "AromaClear Password Reset Notification";
$headers = "From: webmaster#aromaclear.co.uk";
$msg = "Your new password is $newpass\r\nIf you have received this e-mail in error, please ignore it.\r\n.";
if(mail($email, $subject, $msg, $headers))
{
//handle success
}
else
{
//handle failure
}
Change style to your preference.
have you checked the return value of mail(). If it's not FALSE then it's accepted for delivery and the code is fine, but something is messed up somewhere else.
That looks fine to me, perhaps do
if (mail($to_email,$subject,$message, $headers))
echo 'Success';
else
echo 'Error';
}
That might let you know if it's trying to send at all.
Just don't add "\r\n" everywhere, use it only to separate headers.
In the message you can use only \n, it will work.
And at the end of the subject and receiver there's no need for "\r\n".