I'm using CakePHP to send an email. My controller code looks like:
if ($this->User->save($this->request->data)) {
$email = new CakeEmail();
$email->from(array('noreply#mydomain.com' => 'My Domain'));
$email->to($this->request->data['User']['email']);
$email->subject('My Domain Confirmation');
$email->replyTo('noreply#mydomain.com');
$email->sender('noreply#mydomain.com', 'My Domain');
$email->emailFormat('html');
$email->template('confirmation');
$email->send();
$email->viewVars(array(
'name' => $this->request->data['User']['username'],
'id' => $this->User->getLastInsertID(),
'code' => $this->request->data['User']['confirm_code']));
}
I also included at the top of this controller:
App::uses('CakeEmail', 'Network/Email');
If I print_r on $email->send(), I get:
Array
(
[headers] => From: My Domain
Reply-To: noreply#mydomain.com
X-Mailer: CakePHP Email
Date: Thu, 23 Feb 2012 00:40:00 -0800
Message-ID: <4f45fb60a0fc46cd926f305a32396397#mydomain.com>
MIME-Version: 1.0
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit
[message] =>
Hi there,
Welcome to my site! While you can now vote on submissions and leave comments, your own submissions will be screened and not appear to the public until you click on the confirmation link below:
Click here to confirm your account
We hope to see you around and thanks for joining the community!
So it's obviously using my html email template and passing the right variables to it, and throwing no exceptions. So I decided to just do a basic mail() test within one of my view files e.g.:
$to = "mytestemail#example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse#example.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
Which echoed "Mail Sent.", but nothing actually came to my mailbox. I checked my file in /var/spool/mail/root and the last email sent was on the same server on Jan. 9, 2012. So it's definitely worked before. I just recently upgraded to Cake 2.0, but this doesn't explain why plain ol' mail() isn't working.
What other debugging methods can I check to make sure it's not my server preventing the email from being sent?
PHP's mail() won't throw any exceptions. You need to check the return status. If that's false, then your MTA isn't accepting mail. Even if it returns true, that doesn't actually mean much of anything.
Take a look at the mail logs in /var/log/. Hopefully those can help you figure out more.
also check your firewall settings. sometimes it stops all outgoing smtp requests if not from specific sources.
The server you are running your Cake app on probably requires (SMTP) authentication before it allows you to send anything, which is a pretty common configuration.
Copy the app/Config/email.php.default file to app/Config/email.php and adjust it to match your setup (usually it's just localhost and you can use one of your mailbox logins for authentication).
Also see the book on this subject.
Related
I have a simple React application and I would like to create a form that sends an email to a specific Outlook adress without having to add my own backend.
I first looked at email.js, a library that works fine for Gmail but not for Outlook in my case. When I try to set up the correct Email, I get:
412Hotmail: Invalid login: 535 5.7.139 Authentication unsuccessful, SmtpClientAuthentication is disabled for the Tenant. Visit https://aka.ms/smtp_auth_disabled for more information. [MW4PR04CA0143.namprd04.prod.outlook.com]
This leads into a maze of powershell commands that, for reasons that are hard to summarize, were very difficult to follow through and actually make it work.
I then tried using https://www.smtpjs.com/, but I can't make it work with React. The following code:
Email.send({
Host : "smtp.yourisp.com",
Username : "username",
Password : "password",
To : 'email#email.com',
From : "you#isp.com",
Subject : "This is the subject",
Body : "And this is the body"
}).then(
message => alert(message)
);
gives the error that "Email is not defined", it doesn't matter where I insert my script tag, in my component or in index.html. I also tried
const script = document.createElement("script");
script.src = "https://smtpjs.com/v3/smtp.js"
inside the component, still does not work.
The only solution that actually works so far is https://formspree.io/, but it is a sub-par solution where the sender is redirected to a Formspree page.
I have a very vague understanding of SMTP, so perhaps I am making some rookie mistake with smtp.js.
Grateful for any help.
i am trying to sending mail using cakephp 3.0 .
My code is :
Email::configTransport('WebMail',[
'className' => 'Smtp',
'host' => $host,
'port' => $port,
'timeout' => 30,
'username' => $username,
'password' => $password,
'client' => null,
'tls' => null]
);
$transport = ['transport' => 'WebMail'];
$email = new Email($transport);
$email
->from([$username => $senderName])
->to($email_to)
->subject('Password Reset Code');
$response = $email->send('hello');
its working fine but the problem is how to check if the email was delivered successfully or not to the recipient.
if I debug $response variable I got the array of all mail related data.
Now how can I check if the email was delivered or not .
You can't... at least not reliably. All CakePHP can tell you is whether sending/queing the mail was successful, and depending on the transport (Smtp/Mail/...) that you're using you can get the last response received from the E-Mail server.
If sending/queing was unsuccessful, a \Cake\Network\Exception\SocketException exception will be thrown, so catch that if you want to evaluate this problem. Other than that there's no further information CakePHP/PHP can provide you with.
try {
$email->send();
} catch (\Cake\Network\Exception\SocketException $exception) {
// sending/queing failed
// the last response is available when using the Smtp transport
$lastResponse = $email->transport()->getLastResponse();
}
If applicable you could use a custom Smtp transport and implement requesting DSNs (Delivery status notifications, which you could then evaluate later on, however this isn't foolproof either, as notifications aren't guaranteed.
See also
API > \Cake\Mailer\Transport\SmtpTransport::getLastResponse()
API > \Cake\Mailer\Email::transport()
You'll need to add some form of tracking pixel to the email, or just use a transactional email service like Mandrill (MailChimp) or SendGrid...etc that will do this for you. You can then see whether they received it, and if they opened it...etc.
You can manually open the inbox of sending email to check if the mail was sent. If due to any reason the mail could not be sent, you'll receive a revert mail stating the problem.
Now, I know this is not a very efficient method so you need to keep these things in mind :-
1. You need to lower the security of your email.
2. You should not send codes (JavaScript etc) on email.
3. Keep in mind the size of content you are sending.
With these points checked you can assume your mail was sent. For a safer side you can check you mail once a week/month to see if all the mails were sent or if you got any error.
I want to set .config.inc.php of MarketplaceWebServiceOrders library that I used to access order of amazon seller account.
Here is my config.inc.php file setting
/************************************************************************
* REQUIRED
*
* All MWS requests must contain a User-Agent header. The application
* name and version defined below are used in creating this value.
***********************************************************************/
define('APPLICATION_NAME', 'MarketplaceWebServiceOrders');
define('APPLICATION_VERSION', '2013-09-01');
After figure out these setting I got error
Caught Exception: Resource / is not found on this server. API Section is missing or you have provided an invalid operation name. Response Status Code: 404 Error Code: InvalidAddress Error Type: Sender Request ID: 47e5f613-5913-48bb-ac9e-cb00871b36af XML: Sender InvalidAddress Resource / is not found on this server. API Section is missing or you have provided an invalid operation name. 47e5f613-5913-48bb-ac9e-cb00871b36af ResponseHeaderMetadata: RequestId: 47e5f613-5913-48bb-ac9e-cb00871b36af, ResponseContext: 6qut/Q5rGI/7Wa0eutUnNK1+b/1rvHSojYBvlGThEd1wAGdfEtnpP2vbs28T0GNpF9uG82O0/9kq 93XeUIb9Tw==, Timestamp: 2015-09-15T12:47:19.924Z, Quota Max: , Quota Remaining: , Quota Resets At:
Here GetOrderSample.php file code for service url. Which I have done already.
// More endpoints are listed in the MWS Developer Guide
// North America:
$serviceUrl = "https://mws.amazonservices.com/Orders/2013-09-01";
// Europe
//$serviceUrl = "https://mws-eu.amazonservices.com/Orders/2013-09-01";
// Japan
//$serviceUrl = "https://mws.amazonservices.jp/Orders/2013-09-01";
// China
//$serviceUrl = "https://mws.amazonservices.com.cn/Orders/2013-09-01";
$config = array (
'ServiceURL' => $serviceUrl,
'ProxyHost' => null,
'ProxyPort' => -1,
'ProxyUsername' => null,
'ProxyPassword' => null,
'MaxErrorRetry' => 3,
);
$service = new MarketplaceWebServiceOrders_Client(
AWS_ACCESS_KEY_ID,
AWS_SECRET_ACCESS_KEY,
APPLICATION_NAME,
APPLICATION_VERSION,
$config);
Caught Exception: Resource / is not found on this server.
This is telling you that the problem is with the path. It's not being able to find that.
Are you sure that the class you're trying to use is in the right path? Most classes that you need to run the samples are in the "Model" folder.
I mean to say, if you take the sample out of the sample folder and put it elsewhere, it won't be able to find classes in the "Model" folder.
An easy fix to test it is to put everything you downloaded from the MWS site into your web directory and just edit the config file. It should work that way.
I'm not a php guy, but I don't see where you're setting up the access keys, merchant id, marketplace id, and most importantly the serviceURL. The 404 error is the first clue meaning it can't find the service. Download the PHP client library which has everything you need to get started.
I have been trying to print USPS label in ZPLII format using Google Cloud and CakePHP. I have registered my ZP500(ZPL) Thermal printer with the cloud. I am getting base64 encoded ZPLII data from USPS which I am storing in a .txt file after base64 decoding. I am sending Content-Type in cloud as text/plain(as I do t know what type exactly to send). When I send a request to cloud print, I see a request in the printer queue and it says printing. Then after few seconds it disappers from queue without printing anything. In Google cloud it says the page printed successfully. Below is the post fields that i am sending to google print:
$post_fields = array(
'printerid' => $printerid,
'title' => $printjobtitle,
'content' => ($contents),
'contentType' => $contenttype,
'ticket' => '{"version":"1.0","print":{"dpi":{"horizontal_dpi":600,"vertical_dpi":600}, "margins": {"top_microns":1, "right_microns":1, "bottom_microns": 1, "left_microns": 1}, "vendor_ticket_item":[]}}'
);
Can anyone tell what is that I am doing wrong here ?
try with this ticket by giving nothing in the print object this is the default option because in customizing ticket, anything goes wrong it won't print.
{
"version":"1.0",
"print":{}
}
and next, in the content type try using any one of these options, in Cloud Print API doc I see only these when I go through it.
image/pwg-raster (or)
*/* (or)
application/pdf (or)
image/jpeg
any other content type if anybody knows, appreciatable to post in comments. Also, I tried with combo of content type like "image/pwg-raster,application/pdf" it got printed for me.
I am using cakephp, and sending email through cakeemail with smtp. My hosting is on 1and1.com. Email is going to deliver on gmail but not on yahoo and hotmail.
Then I try the PHPMailer on same server and its email was going to deliver on gmail and hotmail as well. But unfortunatly I am unable to use PHPMailer with cakephp. I have try two tutorial but fails. One of them is here.
I will prefer to fix the problem with cakeemail, if some one can help regarding this.
Or if can get solution with PHPMailer for cakephp that is also ok.
Here is the my code
$email = new CakeEmail();
$email->smtp = array(
'port'=>'25',
'timeout'=>'30',
'host' => 'smtp.1and1.com',
'username'=>'quote#xxxxxx.com',
'password'=>'xxxxxx_',
'client' => 'smtp.1and1.com' ,
'transport' => 'Smtp'
);
$email->from(array('xxxx#a-xxxx.com' => 'A-Best Auto Parts Quote'));
$email->to("xxxx#yyy.com");
//$email->bcc("xxxx#yyy.com");
$email->subject('My Test Subject');
$email->emailFormat('html');
$body="the test message for email"
$email->send($body);