I have a register script that sends an email to who ever signs up.
//// Set headers ////
$headers = 'MIME-Version: 1.0' . "rn";
$headers .= "Content-type: textrn";
$headers .= "From: $from";
/// Send the email now ////
mail($email1, $subject, $message, $headers, '-f nleachman#stayontrack.net');
//mail($email1, $subject, $message, $headers, '-f noreply#your-email.com');
$db->commit();
echo "Thanks for joining! Check your email in a few moments to activate your account so that you may log in. See you on the site!";
$db = null;
exit();
}
catch(PDOException $e){
$db->rollBack();
echo $e->getMessage();
$db = null;
exit();
}
Here is my SMTP server used for configuration:
SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = nleachman#stayontrack.net
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
When ever I try to run my log-in script I get this:
Thanks for joining! Check your email in a few moments to activate your account so that you may log in. See you on the site!
My problem is that who ever signs - up never recieves the email. At first I thought that it may just be an impossible function on localhost. Then however, I saw some codes that worked for other people but gave me an error like...
Variable $From not set
How could I configure my code so that it runs without errors?
Also, how could I configure the code to make sure who ever the email is sent to recieves it?
For using SMTP within PHP, you should have a look at phpmailer. https://github.com/Synchro/PHPMailer
easy to configure and does all the work for you.
You're using mail() to send the email - I've had problems with this before not sending to certain domains like hotmail. I'd give PEAR mail a go - http://pear.php.net/package/Mail/redirected.
Related
That is my code for sending email via wp_mail() method
$user_email = $_POST["user_email"];
$subject = 'Account is ready.';
$message = "Hello <b>$user_name</b>,a new account created for you and you need to create a password, <a href'http:example.com/account?email=$user_email'>click here</a> to create a password and login.";
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=iso-8859-1';
$mail = wp_mail($user_email, $subject, $message, $headers);
if($mail){
echo 'Sent email to user.';
}
else {
echo 'Oops something went wrong to sending email.';
}
actually that didn't work I mean not sending the email to user, while modify the wp_mail() method like this
$mail = wp_mail($user_email, $subject, $message);
that's working, that the mean it never taken more than three parameters, but I need to add $headers for HTML.
What can I do now?
Any advise?
Thanks
According to the wp_mail docs the headers parameter is used to set From, CC and BCC fields. It might not set other fields.
To set your content type and character set you need to use another function, please see linked docs.
Mail is send in plain text by default, to send it as HTML you should also consult linked docs as the method to switch to HTML is also there.
Have you setup, SMTP settings in WordPress panel if not you can use Many plugins to setup you can use m fav plugin
https://wordpress.org/plugins/post-smtp/
Try to set up this plugin and after let me know if you still facing those issues
Hi I have used sendgrid to send emails in the past and am using it as a reset password on an app currently. I want to use it for another app also. My AWS has a new instance for the second app. I have copied the sendmail.ini from my first instance and the php.ini and I am using basically the same code for sending emails in my php files. The first is working, the second isn't. Code below:
$subject = "Don't be stuck for a password!" ;
$Emessage = wordwrap("<html><body>Please click the link below to reset your password. <br><br> <a href=http://xxx.xxx.xx/resetPassword.php?AuthCode=".$Token."&email=".$email."&userid=".$userid." />Reset Password</a><br><br> Thanks, <br></body></html>", 70, "\r\n");
$from= "xxx#xxx.com";
$from_name="xxx Ltd.";
$headers = "Date: ". date("r") ."\r\n". "From: $from_name <$from>\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
//echo $message;
$mailSent= mail($email, $subject, $Emessage, $headers);
if (!$mailSent){
//$reset= error_get_last();
$reset='Not OK';
}
Note the mailSent is returning true. It must be some config issue. Also, I am running the same version of xampp on both instances.
My sendmail.ini is as follow:
[sendmail]
smtp_server=smtp.sendgrid.net
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username=xxx
auth_password=yyy
force_sender=xxx#xxx.com
and my php.ini has the following in the [mail function]:
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" - t"
Since the same code is working on one instance and not the other, if we assume the instances are exactly the same, it must be external to your instance. AWS has an initial outbound email limit, so it's possible you're hitting that, but it's been lifted on your other instance.
One way to get around this, is to send via SendGrid's Web API (which is not limited on AWS [as it sends over port 80]).
You won't be able to send using the mail function, however, we have a PHP Library to send email that makes it easy enough to do.
Turns out I made the rookie mistake of not restarting my Apache! That was all that was wrong!
Hi guys i am using the mail() from the contact form and for some reason it is not working.
The php coding i have setup is as follows:
// sending email to sales#xxx.com
$to = "hello#xxx.com";
$subject = 'Email From {$name} from your website';
$message = "$name has contacted you from the website and says:
$mcontent
$name 's contact email address is: $email";
$headers = $email . "\r\n";
$headers .= "Reply-To: " . $email . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
mail($to, $subject, $message, $headers) or die ("Failure");
// end of sending mail
returnheader("/xxx/email-sent");
i get no errors at all, it even goes to the success page when completed.
Any ideas why this would not work.
I have checked your code and it is working fine on my server , i am getting e-mail.
Here , it looks like some problem with your SMTP server settings.
There is nothing wrong with your PHP script.
You can find your solution here.
php.ini & SMTP= - how do you pass username & password
Also in windows environment ,
http://www.ruhanirabin.com/php-sendmail-setup-with-smtp-iis-and-windows-servers/
If you are on WIndows, make sure you have an SMTP server in your
php.ini
If you are una Unix, make sure the MTA is running: If it is (at least partly) installed but not runnng, you will get exactly this effect
Edit
If your MTA is not running, and you start it, the mails sent with PHP will go out! They have beein queued, but not processed.
This is probably related to the mail setup. Do you have a mailserver running on the machine? Check sendmail / smtp_server settings in php.ini.
mail() uses the sendmail, by default: sendmail -t -i
It returns TRUE if the mail has been accepted, not if it has been sent:
Return Values
Returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise.
It is important to note that just because the mail was accepted for delivery, it does NOT mean the mail will actually reach the intended destination.
I would suggest using http://swiftmailer.org/ with SMTP rather than mail().
The first line of $headers is invalid if $email is just an email address. Presumably you would want something like:
$headers = "Cc: " . $email . "\r\n";
or
$headers = "From: " . $email . "\r\n";
The cause can be for example, you don't have setup a mail server, or configuration of firewall if you has it.
You should use double quotes instead of single quotes in the variable $subject
$subject = "Email From {$name} from your website";
I have created a form and written a php script to send a mail after clicking the submit button, and display a thank you message after sending the mail. The "Thank you" message is put into another HTML page.
I put those to WWW folder in WAMP server and try it. The "Thank you" page is displayed but the mail is not sent to my mail account.
Why did it not send my mail? Is it necessary to host the web site to do this?
This is the code that I'm using:
<?php
$email_from = 'aa#gmail.com';
$email_subject = "Arrange new Safari service";
$email_body = "You have received a new message from $name.\n"
$to = "aa#gmail.com";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
mail($to,$email_subject,$email_body,$headers);
header('Location: thanking.html');
?>
Please read here Sending email from localhost
And here http://forums.devshed.com/mail-server-help-111/how-to-set-up-php-ini-to-send-mail-from-106329.html
If you use the php mail() function, you need an smtp server. Right, that might run on you hosting.
You might also use a librairy like http://swiftmailer.org/ to get it easier (you will be able to use remote smtp servers without pain)
There appear to be some syntax errors in the code you have supplied:
$email_from = 'aa#gmail.com';
$email_subject = "Arrange new Safari service";
$email_body = "You have received a new message from $name.\n";
$to = "aa#gmail.com";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
mail($to,$email_subject,$email_body,$headers);
header('Location: thanking.html');
I have attempted to fix the syntax above.
You need to configure PHP to use a working SMTP service in order to send SMTP email.
Basically, it appears that the SMTP configuration for your PHP instance is using default values, which point to localhost. But your local computer doesn't seem to be running an SMTP service. So you'll need to point is to a server that is running one, and one which your application is permitted to use.
You have to configure your php.ini with a valid smtp server and email address.
Check this article http://www.sitepoint.com/advanced-email-php/
I ran into a wee issue when using mail(). I wasn't able to send to addresses off the domain I was hosting the form. I understand this is for security reasons but it makes the creation of a 'send to friend' system a little tough.
Here's what I had working (albeit it only sent to my address):
<?php
$senderName = $_POST['name'];
$friendsEmail = $_POST['friendsEmail'];
if ($_POST['formName'] == 'refer') {
$to = $friendsEmail;
$subject = "$senderName has referred you";
$message = "Message goes here";
$headers = "MIME-Version: 1.0\r\n";
$headers = "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= 'From: Me <no-reply#test.com>' . "\r\n";
mail($to,$subject,$message,$headers);
}
header("Location: referConfirm.html");
?>
I've talked to my hosting company who setup a mail relay (yay!). Trouble is, I have no idea how to get what I working above through a mail relay. I have the following details:
IP: 000.000.000.000
Domain: domain.company.com
UN: username
PW: password
(Details are dummy.)
Can anyone give me a clue?
Thanks,
#rrfive
mail() uses the smtp/sendmail settings found in php.ini. If you need to send it via another smtp, or one with authentication (like in your example) mail is simply not enough.
There are good mailer libraries out there, just to name a few:
Swift Mailer
Zend_Mail
PHPMailer
They are all capable of sending emails via an authenticated smtp server.