send mail using phpmailer yii2 - php

I have installed zyx-phpmailer extension for send mail function in yii2 and working properly. But, when i checked via yii debugger the recipient is empty. If I using swiftmailer, there is no problem, but I must using zyx-phpmailer :(
code :
Yii::$app->mailer->compose()
->setTo('people#blabla.com')
->setFrom('admin#example.com')
->setSubject('Test')
->send();
Result (yii debugger) :
From : admin#example.com
To : empty // <- this is a problem
Subject : Test
Text body (not set)
Successfully sent : Yes
How to solve this issue? I'm still learning using yii2 framework.

Check if your current mailer is actually the new extension and not SwiftMailer, you can trace it at runtime by calling this Yii::trace(Yii::$app->get('mailer')). Maybe you did not fully configure it.
Try ->setTo(['people#blabla.com' => 'People Blabla']). The first one being the email address itself and the second one being the name.

it work;try
Yii::$app->mail->compose()
->setFrom(['xx#xx.com' => 'My Example Site'])
->setTo([$form->email => $form->name])
->setSubject($form->subject)
->setTextBody($form->text)
->send();

Related

What does this email from SendGrid is refering to in PHP API?

a few days a go we received a email from sendgrid stating they are going to change some behaviors in their API, I've done research but I have not found concretly what they are refering to, currently we are using the PHP API, and atleast for the 2) I think we are OK as we use SendGrid classes to build the emails
Check your code that uses the mail send endpoint and ensure that the
“enable” parameter is included under the filter when applicable.
What do you need to do?
To avoid disruption to your mail send service, please be sure to make
the following actions before August 10, 2021
Check your code that uses the mail send endpoint and ensure that the
“enable” parameter is included under the filter when applicable.
Check your mail send header to ensure that you are using just one
X-SMTPAPI header and address header of the same kind. Remove multiple
headers of the same kind, so you have only 1 header of the same kind.
For example, if you are currently using multiple “from” headers, you
should modify your code so that you have a single “from” header.
Check your code to ensure that you are not applying any
personalization block substitution to your custom argument fields.
But what about the third item? we have substitions of following fashion: $mail->personalization[0]->addSubstitution('%url%', $link);
But I havent found anything like a "block sustitution in custom arguments"
And the first item also worries me, I haven't found anything like that neither, so I'm afraid that perhaps there is something that the PHP API does behind the scenes.
This a example of the code we use.
$sendgrid = new SendGrid(env('SENDGRID_APIKEY'));
$from_m = new SendGrid\Email(null, $from);
$to_m = new SendGrid\Email(null, $from);
$content = new SendGrid\Content("text/html", $body);
$mail = new SendGrid\Mail($from_m, '.', $to_m, $content);
$mail->personalization[0]->addBcc($tos);
$mail->personalization[0]->setSubject($subject);
$mail->personalization[0]->addSubstitution('%MemberName%', $name);
$mail->personalization[0]->addSubstitution('%url%', $hash_url);
$mail->setTemplateId($template_id);
$sendgrid->client->mail()->send()->post($mail);
We are using sendgrid/sendgrid: ~6.2
Twilio SendGrid developer evangelist here.
From my reading of your code and the guidelines you've been sent, you should be ok.
You don't appear to be using anything that needs to be enabled via the API, though you can check all the mail_settings and tracking_settings in the API reference here.
As you are using the library and calling the API you don't appear to be sending any extra headers.
You don't seem to be using any custom arguments, so you aren't applying any substitutions to them.
I do recommend that you upgrade your PHP helper library to version 7 from 6. That will ensure that the underlying library is also using the API in the most up to date manner.

Mailgan email validation message":"Validations are not enabled."

I'm trying to use Email validator from Mailgun in my laravel project.
I'm following the documentation here https://documentation.mailgun.com/en/latest/api-email-validation.html#request-examples. But I'm always getting a message ": "Validations are not enabled.". I've tried the examples from the documentation for PHP and curl, but the result is the same "Validations are not enabled."
Does anyone know what is the problem?

How to send message from WhatsApp in PHP with WhatsAPI Official?

I'm trying to use the WhatsApi Official library to send a message via WhatsApp from a php file. I've moved in my Apache web server the library, in a folder call test, like this:
The file whatsapp.php is this one:
<?php
require_once './src/whatsprot.class.php';
$username = "1XXXXXXXXX";
$password = "password";
$w = new WhatsProt($username, "0", "My Nickname", true); //Name your application by replacing “WhatsApp Messaging”
$w->connect();
$w->loginWithPassword($password);
$target = '1xxxxxxxxx'; //Target Phone,reciever phone
$message = 'This is my messagge';
$w->SendPresenceSubscription($target); //Let us first send presence to user
$w->sendMessage($target,$message ); // Send Message
echo "Message Sent Successfully";
?>
I'm facing some problem with the library new WhatsProt(), which blocks all the code (may be sockets ?).
So my question is, how can I fix this problem ? If no, are there any other solution to send message from a pho script ?
You can use below script to send message from whatsapp in PHP.
https://github.com/venomous0x/WhatsAPI/tree/master/examples
Configure the source code in Apache and run examples/whatsapp.php file.
You have change below configurations.
//simple password to view this script
$config['webpassword'] = 'MakeUpPassword';
and
$config['YOURNAME'] = array(
'id' => 'e807f1fcf82d132f9bb018ca6738a19f',
'fromNumber' => '441234567890',
'nick' => "YOURNICKNAME",
'waPassword' => "EsdfsawS+/ffdskjsdhwebdgxbs=",
'email' => 'testemail#gmail.com',
'emailPassword' => 'gmailpassword'
);
It's working for me..
afaik you are probably better off currently writing an interface to a python project. E.g. have a microservice that does sending of messages for you in python, and you call them via some json request or similar
see this project, looks promising: https://github.com/tgalal/yowsup
it seems like the only viable option so far, as everything else was shut down or has a high probability to get your account banned
see discussion here:
https://stackoverflow.com/a/46635985/533426

Google App Engine PHP Message Service - From name support

I need set sender name, but I have errors when I used this:
$mail=new \google\appengine\api\mail\Message();
$mail->setSender("Sender Name <email#address.com>");
same problem, if I tried modify headers:
$mail->addHeader("From", "Sender Name <email#address.com>");
Somebody who solved this problem?
Thanks
This is a known issue in GAE PHP, you can track it at https://code.google.com/p/googleappengine/issues/detail?id=10153

Sending emails with mailgun and Laravel

I am trying to learn how to send emails using Mailgun in Laravel. When I try to send the email I get a timeout that says: Maximum execution time of 60 seconds exceeded
The application times out here:
$line = fgets($this->_out);
I have a route that activates when I click a button on my email page:
Route::post('/email', 'MainController#sendEmail');
Here is my controller function (replaced my email for privacy reasons):
public function sendEmail() {
$data = [
'title'=>'Email'
];
Mail::send('emails.hello', $data, function($message) {
$message->from('example#gmail.com', 'Example Person');
$message->to('example#gmail.com')->subject('we made it');
});
return Redirect::to('/');
}
Any ideas on what I may do be doing wrong?
This generally happens if the SMTP port used in the app/config/mail.php config file is not opened by your hosting provider. Please check and ask them to open the port. This should resolve the issue.
Sending emails through mailgun could not be simpler, just add the API package, publish and update the config and use the custom facade to send them (changing Mail::send() to Mailgun::send())
You can find the package here: http://packalyst.com/packages/package/vtalbot/mailgun
I know this doesn't really address the error your getting (would need more information to help with that), but using the package does simplify the whole thing!

Categories