The problem I am facing at the moment is really odd.
I've used the script given below before and it has worked like a charm, but now it is simply not working.
Here is the code:
function send($str){
$from = "body<body#gmail.com>";
$to = "TargetName <matthew.s#gmail.com>";
$subject = "Questionnaire Submission!";
$body = $str;
$host = "smtp.gmail.com";
$username = "body";
$password = "pwd";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("An error occured during submission! Please try again!");
} else {
echo("Submission Successful!!\nYou will now be redirected to a page to fix the timings.");
}
}
Now this code wont send the mail can I cannot understand why.
Some help would be appreciated.
Best Regards
Priyabrata
edit
I received a mail from the account I was using to send the mail :
This is an automatically generated Delivery Status Notification
THIS IS A WARNING MESSAGE ONLY.
YOU DO NOT NEED TO RESEND YOUR MESSAGE.
Delivery to the following recipient has been delayed:
Message will be retried for 2 more day(s)
Technical details of temporary failure:
Message temporarily rejected. See http://support.google.com/mail/bin/answer.py?answer=69585 for more information.
This has nothing to do with PEAR mail; it's a general email issue.
PEAR's Mail package can send mails fine - also with recent PHP versions like 5.5 and 5.6beta1.
Try to send the mail to a different email address, this might work.
Also follow Gmail's guidelines as depicted in the support URL in your response.
In situations where the recipient is a Gmail user, we will include:
...
So send the mail to a gmail address, and you will get more information.
Related
I am having some trouble figuring out why my emails are not being sent out to my Office 365 account. Before my companies migration to Office 365 we had an internal mail server and getting emails to send out was a piece of cake. However, now that we have moved to Office 365 it has become a real headache getting emails to send out. I thought that maybe I needed to set up an SMTP Relay and point to that server in my php code but it seems that is not the issue. Below is my code used to send out a test email:
$from = "example#example.com";
$to = "test_user#example.com";
$bcc = '';
$subject = "Hi!";
$body = "Hi,\n\nLooks like it worked.";
$host = 'smtp.office365.com';
$port = '587';
$username = 'example#example.com';
$password = '**********';
$headers = array(
'Port' => $port,
'From' => $from,
'To' => $to,
'Subject' => $subject,
'Content-Type' => 'text/html; charset=UTF-8'
);
$recipients = $to.", ".$bcc;
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($recipients, $headers, $body);
echo "test";
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
Once I run this code I am presented with the following error:
authentication failure [SMTP: SMTP server does not support authentication (code: 250, response: SN1PR19CA0003.outlook.office365.com Hello [68.15.136.46] SIZE 157286400 PIPELINING DSN ENHANCEDSTATUSCODES XXXXXXXA 8BITMIME BINARYMIME XXXXXXXB)]
I have researched the heck out of this error and have had no luck in resolving my issue. I am wondering if it has something to do with the fact that the server I am generating the php code on is a development server and not on a live site. I am thinking that since this is not a live site I need to point it to a server that uses SMTP relay in order to get it out onto the internet, however, like I said I have had no luck when doing this.
Any assistance is greatly appreciated.
Thanks in advance.
I have google apps setup for one of my site's emails, thus making the site's built-in email routing useless when doing things from the web. What i need to do , is have it use ssl/smtp to connect to the google apps setup.
To accomplish this, I've used PEAR Mail and mime (for the HTML contents).
The messages get sent without an issue... the ONLY problem i'm having, is that the 'From' header isn't being saved across transmission. Instead, the account email is in the 'from' header.
The accounts exist on the webserver's end (which means nothing since its all going through google), and i've added aliases to my gmail apps administration end. But no matter what i do, its not changing the 'from'.
Is this just something i'm going to run into when using a single account with google apps' gmail? (--forced 'from' from the account name?)
Thanks
--for those who were wondering, here is an example function for the mail sending:
function pearMail($from, $fromTitle, $to, $subject, $text, $html)
{
require_once "Mail.php";
require_once('Mail/mime.php');
$host = "ssl://smtp.gmail.com";
$port = "465";
$username = "name#domain.com";
$password = "PASSWORD";
$headers = array ('From' => $from,
'Return-Path' => '-do not reply-',
'To' => $to,
'Subject' => $subject);
$crlf = "\n";
// Creating the Mime message
$mime = new Mail_mime($crlf);
// Setting the body of the email
$mime->setTXTBody($text);
$mime->setHTMLBody($html);
$body = $mime->get();
$headers = $mime->headers($headers,true);
// Sending the email
$mail =& Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
$mail->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
}
See the google help on changing From::
The custom 'From:' feature works only if you already own the account linked to the alternate address. To send mail with a different Gmail username, you must first sign up for that address.
I want, that users who register on my site, have to activate their account first, before using it. The problem is, that I don't get any email to my email test account.
Before I start posting a code, could the problem be, that I'm working currently on a local machine with xampp?
Otherwise, here is the code snippet
$random = substr(number_format(time() * rand(),0,'',''),0,10);
$insertMailVerify = $this->db->prepare("INSERT INTO mailverify (mailAddress, token, datetime) VALUES (:mailAddress, :token, :date)");
$insertMailVerify->execute(array(':mailAddress'=>$emailAddress,
':token'=>$random,
':date'=>$date));
$to = $emailAddress;
$subject = "Activating your Account";
$body = "Hi, in order to activate your account please visit http://localhost/FinalYear/activation.php?email=".$emailAddress." and fill in the verification code $random";
if(mail($to, $subject, $body))
{
echo ("<p>Message success</p>");
}
else {
echo ("<p>Message fail</p>");
}
Just in case you wonder where i take $emailAddress from: This is just a code snippet, i already let the software echo the email address, and it's correct. It even goes in the "Message success" if case, but I still can't get any email. What could be the problem?
After submit the form you can use a code or link and send it to the user email id
$message = "Your Activation Code is ".$code."";
$to=$email;
$subject="Activation Code For Talkerscode.com";
$from = 'your email';
$body='Your Activation Code is '.$code.' Please Click On This link Verify.php?id='.$db_id.'&code='.$code.'to activate your account.';
$headers = "From:".$from;
mail($to,$subject,$body,$headers);
echo "An Activation Code Is Sent To You Check You Emails";
Code from TalkersCode.com for complete tutorial visit http://talkerscode.com/webtricks/account-verification-system-through-email-using-php.php
in local host i think the best way is using phpmailer and gmail account
here the tutorial : http://www.web-development-blog.com/archives/send-e-mail-messages-via-smtp-with-phpmailer-and-gmail/
It seems your mail server SMTP is not configured correctly....
check the port and IP of SMTP server address.
Try to change you PHP.ini file like this and tell me if it works.
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = smtp.gmail.com
; http://php.net/smtp-port
smtp_port = 465 //if 465 is not working then try 25
If this is not working then there are a lot of tutorials of how to achieve what you are trying to do.
Here is one link: Send email from localhost
Had the same problem, but on linux.
1) Assuming your mail() function is working properly: the problem could be, that email is coming into spam-box (because these localhost mail systems are often marked as spambots, so email services are protecting emails from unverified host).
2) If mail() is not working, its not configured properly, if you follow some tutorial and configure it, which needs like 5 minutes, you will realise why not to use it:)
The best way for you is to use some free or paid smtp service. Very easy, quick and your emails wont be marked as spam. And install PEAR library to send email. Here is an example.
$from = 'from#domain.com';
$to = 'to#domain.com';
$subject = 'subject';
$body = 'Hello!';
$host = 'smtpserver.com';
$port = '25';
$username = 'yourlogin';
$password = 'yourpass';
$headers = array ('From' => $from, 'To' => $to, 'Subject' => $subject);
$smtp = Mail::factory('smtp', array ('host' => $host, 'port' => $port, 'auth' => true, 'username' => $username, 'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if(PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
To your verification code: instead of telling user to write down the verification code, better generate him the link, that he clicks his account gets activated. Something like
http://localhost/FinalYear/activation.php?email=some#email.com&token=79054025255fb1a26e4bc422aef54eb4
on registration page: generate the activation token like md5($email . '_sometext');
on activation page if(md5($_GET['email'] . '_sometext') == $_GET['token']) { activate.. }
please note, that it is just an example, there are 10 ways how it could be done :)
I'm working on a script that will send text messages via email (i.e. ####txt.att.net) and PHP's simple mail() function was not working. I could send email messages just fine through that method, but the texts were not being delivered. I did more research and found that carriers often block messages without a sender and using PEAR with SMTP is a better solution.
However, the following code works to send emails but is still not delivering AT&T text messages:
<?php
require_once "Mail.php";
$from = "XXX <XXX>";
$to = "XXX <XXX#txt.att.net>";
$subject = "Test email using PHP SMTP\r\n\r\n";
$body = "This is a test email message";
$host = "XXX";
$port = "26";
$username = "XXX";
$password = "XXX";
$headers = array (
'From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array (
'host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
?>
Is it maybe an issue with headers not being formatted correctly, etc? Any ideas?
According to their example you do not need the new lines after the subject:
http://pear.php.net/manual/en/package.mail.mail.send.php
Check the AT&T response they might decline it if they have you blacklisted or you do not have a valid rDNS or other reasons.
They seem to experience a problem seeing the rDNS records of some IP's.
Use this it will tell you all the info you need.
http://wordpress.org/extend/plugins/xmail-the-right-way
Post the log of it here.
First off, the server: Exchange 2003 sp2 running on Windows 2003 Server sp2
I have a script that sends email to two email accounts, one called students# and the other being fs# (faculty/staff). We are setting both those email accounts to only accept incoming email by authenticated users on the exchange server, to spare ourselves from spam/junk mail. So right now the emails being sent by the script are not successful. I have the return-path email as a legit user, but it is not authenticated. I noticed that when I tried sending a test via my mail client (Apple's Mail.app) and since I use email through their IMAP server and not through exchange, my email failed as well.
Here is the code for sending the email:
$mail = new htmlMimeMail();
$message = $today.$announcements.$food.$upcoming;
$mail->setHTML($message);
$mail->setSubject($subject);
$mail->setSMTPParams('mail.domain.com', 25, true, 'user', 'pass');
$mail->setFrom("no-reply#domain.com");
$mail->setReturnPath("webmaster#domain.com");
if($message)
$mailresult = $mail->send(array($emailto));
I have never authenticated with an exchange server using the HTML Mime Mail for PHP (http://www.phpguru.org/static/mime.mail.html) class before. Any help would be appreciated.
Maybe there is another PHP class that easily allows authentication with an Exchange server?
EDIT: Are there any php mail classes out there that authenticate properly with an exchange server?
Another EDIT: The Exchange Server uses NTLM authentication and uses Active directory. Hope this helps.
Exchange supports the standard SMTP Auth mechanism, so I would use that. Here is an example using Pear::Mail from here.
<?php
require_once "Mail.php";
$from = "Sandra Sender <sender#example.com>";
$to = "Ramona Recipient <recipient#example.com>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$host = "mail.example.com";
$username = "smtp_username";
$password = "smtp_password";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
?>