This is not a duplicate question I have tried a lot with GAE Php mail send but find exception below is not an authorized email address. I have tried with all email ids.
ot sendexception 'InvalidArgumentException' with message 'Mail Service Error: Sender (info#mywebsite.in) is not an authorized email address.' in /base/data/home/runtimes/php/sdk/google/appengine/api/mail/BaseMessage.php:336 Stack trace: #0 /base/data/home/runtimes/php/sdk/google/appengine/api/mail/Message.php(148): google\appengine\api\mail\BaseMessage->handleApplicationError(Object(google\appengine\runtime\ApplicationError)) #1 /base/data/home/apps/s~acuteservice-1260/1.393973634644018844/contact.php(38): google\appengine\api\mail\Message->send() #2 {main}
Below is my code that through above InvalidArgumentException
<?php
use google\appengine\api\mail\Message;
$name=$email=$query="";
if($_SERVER["REQUEST_METHOD"]=="POST"){
$name = $_POST["name"];
$email = $_POST["email"];
$query = $_POST["message"];
require_once 'google/appengine/api/mail/Message.php';
$mail_options = [
"sender" => "info#mywebsite.in",
"to" => "isashi4u#gmail.com",
"subject" => "Subject",
"textBody" => $query,
];
try {
$message = new Message($mail_options);
$message->send();
} catch (InvalidArgumentException $e) {
echo "not send";
echo $e;
}
}?>
is there any way to give default setting on "sender" mail_option ?
Related
use PHPMailer\PHPMailer\PHPMailer;
use Aws\Ses\SesClient;
use Aws\Ses\Exception\SesException;
require 'vendor/autoload.php';
if(!function_exists("sendmailalexraw")){
function sendmailalexraw($email,$subject,$messages,$definesender)
{
// Replace sender#example.com with your "From" address.
// This address must be verified with Amazon SES.
$sender = $definesender;
$sendername = 'Alex';
// Replace recipient#example.com with a "To" address. If your account
// is still in the sandbox, this address must be verified.
$recipient = $email;
// Specify a configuration set.
$configset = 'ConfigSet';
// Replace us-west-2 with the AWS Region you're using for Amazon SES.
$region = 'eu-west-1';
$subject = $subject;
$htmlbody = <<<EOD
<html>
<head></head>
<body>
<h1>Hello!</h1>
<p>Please see the attached file for a list of customers to contact.</p>
</body>
</html>
EOD;
$textbody = <<<EOD
Hello,
Please see the attached file for a list of customers to contact.
EOD;
//// The full path to the file that will be attached to the email.
$att = 'path/to/customers-to-contact.xlsx';
// Create an SesClient.
$client = SesClient::factory(array(
'version'=> 'latest',
'region' => $region
));
// Create a new PHPMailer object.
$mail = new PHPMailer;
// Add components to the email.
$mail->setFrom($sender, $sendername);
$mail->addAddress($recipient);
$mail->Subject = $subject;
$mail->Body = $htmlbody;
$mail->AltBody = $textbody;
$mail->addAttachment($att);
$mail->addCustomHeader('X-SES-CONFIGURATION-SET', $configset);
// Attempt to assemble the above components into a MIME message.
if (!$mail->preSend()) {
echo $mail->ErrorInfo;
} else {
// Create a new variable that contains the MIME message.
$message = $mail->getSentMIMEMessage();
}
// Try to send the message.
try {
$result = $client->sendRawEmail([
'RawMessage' => [
'Data' => $messages
]
]);
// If the message was sent, show the message ID.
$messageId = $result->get('MessageId');
echo("Email sent! Message ID: $messageId"."\n");
} catch (SesException $error) {
// If the message was not sent, show a message explaining what went wrong.
echo("The email was not sent. Error message: "
.$error->getAwsErrorMessage()."\n");
}
}
}
$email='example#gmail.com';
$subject='abc';
$messages='xyz';
$definesender='info#verifieddomain.net';
sendmailalexraw($email,$subject,$messages,$definesender);
?>
I am trying to send RawMessage with Amazon SES but I get :
The email was not sent. Error message: Missing required header 'From'.
Sender I use it's verified, my Amazon SES it's active (out of sendbox ) .
I am needing to send as RAW Message to create unsubscribe option for emails I am sening. As I read from documentation it have to be raw email to be able to add this parameters.Thank you !
You have to base64 encode the message :
$result = $client->sendRawEmail([
'RawMessage' => [
'Data' => base64_encode($messages)
]
]);
Since you're using AWS Ses, you could do it this way:
define('SENDER', 'Your name<a#a.com>');
define('RECIPIENT', 'b#b.com');
define('CCLIST', 'c#c.com');
define('REGION','your region');
define('SUBJECT','Your subject goes here');
$bodytext = "<h2>Your body goes here.</h2>" . PHP_EOL;
$bodytext .= "<p>Append as many rows as you want</p>";
define('BODY',$bodytext);
$client = SesClient::factory(array(
'version'=> 'latest',
'region' => 'your region'
));
$request = array();
$request['Source'] = SENDER;
$request['Destination']['ToAddresses'] = array(RECIPIENT);
$request['Destination']['CcAddresses'] = array(CCLIST);
$request['Message']['Subject']['Data'] = SUBJECT;
$request['Message']['Body']['Html']['Data'] = BODY;
try {
$result = $client->sendEmail($request);
$messageId = $result->get('MessageId');
echo("Email successfully sent! Message ID: $messageId"."\n");
} catch (Exception $e) {
echo("The email was not sent. Error message: ");
echo($e->getMessage()."\n");
}
I have this form on my site:
https://bootstrapious.com/p/bootstrap-recaptcha
I want to add SMTP thanks to this:
https://www.lifewire.com/send-email-from-php-script-using-smtp-authentication-and-ssl-1171197
How to add this to the file contact.php (below) ?. He works independently. I need the form from Bootstrap to send emails via SMTP.
The smtp connection is correct. Only I can not deal with sending all data from the form in this way. This is done using the normal php mail function.
require_once "Mail.php";
$from = "Sandra Sender <mail#mail>";
$to = "Ramona Recipient <mail#mail>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$host = "host";
$username = "mail";
$password = "haslo";
$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>");
}
contact.php
<?php
// require ReCaptcha class
require('recaptcha-master/src/autoload.php');
// configure
// an email address that will be in the From field of the email.
$from = 'Demo contact form <--->';
// an email address that will receive the email with the output of the form
$sendTo = 'Demo contact form <--->';
// subject of the email
$subject = 'New message from contact form';
// form field names and their translations.
// array variable name => Text to appear in the email
$fields = array('name' => 'Name', 'surname' => 'Surname', 'phone' => 'Phone', 'email' => 'Email', 'message' => 'Message', 'name2' => 'Name2', 'surname2' => 'Surname2', 'selekt' => 'Wybrane');
$selectOption = $_POST['selekt'];
// message that will be displayed when everything is OK :)
$okMessage = 'Contact form successfully submitted. Thank you, I will get back to you soon!';
// If something goes wrong, we will display this message.
$errorMessage = 'There was an error while submitting the form. Please try again later';
// ReCaptch Secret
$recaptchaSecret = '---';
// let's do the sending
// if you are not debugging and don't need error reporting, turn this off by error_reporting(0);
error_reporting(E_ALL & ~E_NOTICE);
try {
if (!empty($_POST)) {
// validate the ReCaptcha, if something is wrong, we throw an Exception,
// i.e. code stops executing and goes to catch() block
if (!isset($_POST['g-recaptcha-response'])) {
throw new \Exception('ReCaptcha is not set.');
}
// do not forget to enter your secret key from https://www.google.com/recaptcha/admin
$recaptcha = new \ReCaptcha\ReCaptcha($recaptchaSecret, new \ReCaptcha\RequestMethod\CurlPost());
// we validate the ReCaptcha field together with the user's IP address
$response = $recaptcha->verify($_POST['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']);
if (!$response->isSuccess()) {
throw new \Exception('ReCaptcha was not validated.');
}
// everything went well, we can compose the message, as usually
$emailText = "You have a new message from your contact form\n=============================\n";
foreach ($_POST as $key => $value) {
// If the field exists in the $fields array, include it in the email
if (isset($fields[$key])) {
$emailText .= "$fields[$key]: $value\n";
}
}
// All the neccessary headers for the email.
$headers = array('Content-Type: text/plain; charset="UTF-8";',
'From: ' . $from,
'Reply-To: ' . $from,
'Return-Path: ' . $from,
);
// Send email
mail($sendTo, $subject, $emailText, implode("\n", $headers));
$responseArray = array('type' => 'success', 'message' => $okMessage);
}
} catch (\Exception $e) {
$responseArray = array('type' => 'danger', 'message' => $e->getMessage());
}
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
$encoded = json_encode($responseArray);
header('Content-Type: application/json');
echo $encoded;
} else {
echo $responseArray['message'];
}
Log errors:
PHP Fatal error: Uncaught Error: Class 'Mail' not found in /home/lukaste/domains/lukaste.vdl.pl/public_html/luw2/contact.php:88, referer: http://lukaste.vdl.pl/luw2/
mod_fcgid: stderr: Stack trace:, referer: http://lukaste.vdl.pl/luw2/
mod_fcgid: stderr: #0 {main}, referer: http://lukaste.vdl.pl/luw2/
mod_fcgid: stderr: thrown in /home/lukaste/domains/lukaste.vdl.pl/public_html/luw2/contact.php on line 88, referer: http://lukaste.vdl.pl/luw2/
File does not exist: /home/lukaste/domains/lukaste.vdl.pl/public_html/404.shtml, referer: http://lukaste.vdl.pl/luw2/
Line 88:
$smtp = Mail::factory('smtp',
All send mail:
// Send email
require_once "Mail.php";
$from = "Sandra Sender <kontakt#graftet.pl>";
$to = "Ramona Recipient <lukaste90#gmail.com>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$host = "s12.linuxpl.com";
$username = "kontakt#graftet.pl";
$password = "eRsPdWgB";
$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>");
}
$responseArray = array('type' => 'success', 'message' => $okMessage);
}
} catch (\Exception $e) {
$responseArray = array('type' => 'danger', 'message' => $e->getMessage());
}
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
$encoded = json_encode($responseArray);
header('Content-Type: application/json');
echo $encoded;
} else {
echo $responseArray['message'];
}
/ edit, contact.php with phpmailer. No errors in the logs. The form does not send.
<?php
// require ReCaptcha class
require('recaptcha-master/src/autoload.php');
// configure
// an email address that will be in the From field of the email.
$from = 'Demo contact form <lukaste90#gmail.com>';
// an email address that will receive the email with the output of the form
$sendTo = 'Demo contact form <lukaste90#gmail.com>';
// subject of the email
$subject = 'Wiadomość z formularz wps.lublin.uw.gov.pl';
// form field names and their translations.
// array variable name => Text to appear in the email
$fields = array('name' => 'Imię', 'surname' => 'Nazwisko', 'phone' => 'Telefon', 'email' => 'Email', 'message' => 'Wiadomość', 'pesel' => 'PESEL', 'sprawa' => 'Numer sprawy', 'rodzaj' => 'Rodzaj zapytania', 'dotyczy' => 'Dotyczy');
// message that will be displayed when everything is OK :)
$okMessage = 'Contact form successfully submitted. Thank you, I will get back to you soon!';
// If something goes wrong, we will display this message.
$errorMessage = 'There was an error while submitting the form. Please try again later';
// ReCaptch Secret
$recaptchaSecret = '6LcqdV4UAAAAAOWvJblsdZuxVTHJr3-uDCXutqxM';
// let's do the sending
// if you are not debugging and don't need error reporting, turn this off by error_reporting(0);
error_reporting(E_ALL & ~E_NOTICE);
try {
if (!empty($_POST)) {
// validate the ReCaptcha, if something is wrong, we throw an Exception,
// i.e. code stops executing and goes to catch() block
if (!isset($_POST['g-recaptcha-response'])) {
throw new \Exception('ReCaptcha is not set.');
}
// do not forget to enter your secret key from https://www.google.com/recaptcha/admin
$recaptcha = new \ReCaptcha\ReCaptcha($recaptchaSecret, new \ReCaptcha\RequestMethod\CurlPost());
// we validate the ReCaptcha field together with the user's IP address
$response = $recaptcha->verify($_POST['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']);
if (!$response->isSuccess()) {
throw new \Exception('ReCaptcha was not validated.');
}
// everything went well, we can compose the message, as usually
$emailText = "You have a new message from your contact form\n=============================\n";
foreach ($_POST as $key => $value) {
// If the field exists in the $fields array, include it in the email
if (isset($fields[$key])) {
$emailText .= "$fields[$key]: $value\n";
}
}
// All the neccessary headers for the email.
$headers = array('Content-Type: text/plain; charset="UTF-8";',
'From: ' . $from,
'Reply-To: ' . $from,
'Return-Path: ' . $from,
);
// Send email
//error_reporting(E_ALL);
error_reporting(E_STRICT);
date_default_timezone_set('America/Toronto');
require_once('../class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$mail = new PHPMailer();
$body = file_get_contents('contents.html');
$body = eregi_replace("[\]",'',$body);
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "serwer"; // SMTP server
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Host = "serwer"; // sets the SMTP server
$mail->Port = 26; // set the SMTP port for the GMAIL server
$mail->Username = "#"; // SMTP account username
$mail->Password = "pass"; // SMTP account password
$mail->SetFrom('mail', 'First Last');
$mail->AddReplyTo("mail","First Last");
$mail->Subject = "Wiadomosc";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$address = "mail";
$mail->AddAddress($address, "John Doe");
$mail->AddAttachment("images/phpmailer.gif"); // attachment
$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
$responseArray = array('type' => 'success', 'message' => $okMessage);
}
} catch (\Exception $e) {
$responseArray = array('type' => 'danger', 'message' => $e->getMessage());
}
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
$encoded = json_encode($responseArray);
header('Content-Type: application/json');
echo $encoded;
} else {
echo $responseArray['message'];
}
I am trying to set up a mail system with Amazon SES service. All is good and working if I use only the email address in "Source" parameter. If I try to add a name, I get a 403 Forbidden HTTP error.
In my PHP code I use AWS SDK:
$client = Aws\Ses\SesClient::factory(array(
'key' => 'MYAWSKEYXXXXXXXXXX',
'secret' => 'MYAWSSECRETXXXXXXXXXXX',
'version'=> 'latest',
'region' => 'us-east-1'
));
$request = array();
$request['Source'] = "sender#example.com";
$request['Destination']['ToAddresses'] = array("receiver#example.com");
$request['Message']['Subject']['Data'] = 'Mail Subject';
$request['Message']['Body']['Html']['Data'] = 'mail body in HTML: <b>Hello!</b>';
try {
$result = $client->sendEmail($request);
$messageId = $result->get('MessageId');
$message = "Email sent! Message ID: $messageId";
} catch (Exception $e) {
$message = "The email was not sent. Error message: ";
$message .= $e->getMessage();
}
This code works great, because I have correctly set up my email source in the AWS console with the correct policy. So "sender#example.com" in this example can correctly send the email.
Then, if I try to add a name to the "Source" param, I don't have any success. I tried:
$request['Source'] = "My Name <sender#example.com>";
OR
$request['Source'] = "'My Name' <sender#example.com>";
OR
$request['Source'] = "'My Name'<sender#example.com>";
OR
$request['Source'] = "'My Name <sender#example.com>'";
OR
$request['Source'] = '"My Name" <sender#example.com>';
OR
$request['Source'] = '"My Name"<sender#example.com>';
OR
$request['Source'] = '"My Name <sender#example.com>"';
None of the above work.
Does anybody have any idea on how to use SES sendEmail with email names?
Some answers I saw here, like this one, simply don't work. I need to use sendEmail and PHP SDK.
I'm trying to configure Swift Mailer to send form data to my email account
In short: I have a website, using which I am going to sell some stuff in my local city
There are 3 simple forms that appear when 'Buy' button is active
The point is to send data, filled in these forms directly to my email account,
Being a newbie to PHP, I have tried for several days to make this simple script work, but it ended up a failure
here is the code of mail.php:
<?php
$name=$_POST["name"];
$email=$_POST["email"];
$phone=$_POST["phone"];
if (isset ($name))
{
$name = substr($name,0,30);
if (empty($name))
{
echo "<center><b>Invalid name<p>";
echo "<a href=index.php>Come back and fill up the form properly</a>";
exit;
}
}
else
{
$name = "Invalid name";
}
if (isset ($email))
{
$email = substr($email,0,30); //Не может быть более 20 символов
if (empty($email))
{
echo "<center><b>Email Invalid!<p>";
echo "<a href=index.php>Try again</a>";
exit;
}
}
else
{
$email = "Invalid";
}
if (isset ($phone))
{
$phone = substr($phone,0,15);
if (empty($phone))
{
echo "<center><b>Empty message!!!<p>";
echo "<a href=index.php>Try again</a>";
exit;
}
}
else
{
$phone = "invalid";
}
$i = "invalid";
if ($name == $i AND $email == $i AND $phone == $i)
{
echo "Error! No data was transferred to the script";
exit;
}
$to = "zakaz#playpad2.ru";
$subject = "New order ";
$message = "Name:$name::::::::::Email:$email::::::::::Phone No:$phone:::::::::;
require_once 'lib/swift_required.php';
$transport = Swift_SmtpTransport::newInstance('smtp.yandex.ru', 465, 'ssl')
->setUsername('zakaz#playpad2.ru')
->setPassword('jhfy;tdjtujdyj');
$mailer = Swift_Mailer::newInstance($transport);
// Create a message
$message = Swift_Message::newInstance('Wonderful Subject')
->setFrom(array('kirabidzu#gmail.com' => 'PlayPad 2 Kids tablet order'))
->setTo(array('zakaz#playpad2.ru', 'zakaz#playpad2.ru' => 'A name'))
->setBody('Name:$name::::::::::Email:$email::::::::::Phone No:$phone:::::::::');
// Send the message
$numSent = $mailer->send($message);
if (!$numSent) {
print "Can't send a message";
}
echo "<center><b>Thank you<a href=index.php>Proceed</a> to continue...>";
exit;
?>"
here is a form, located on the main page:
<form name="form" action="mail.php" method="POST"><b>Name here </b>
<br> <input type="text" size="70%" name="name" maxlength="45"> <br>
<b>Phone No </b>
<br> <input type="text" size="70%" name="phone" maxlength="15"> <br>
<b>E-Mail </b>
<br> <input type="text" size="70% " name="email" maxlength="45"> <br>
<input type="submit"><div class="button"></div>
Please help!
Changed smtp server port, and a new error appears:
PHP Fatal error: Uncaught exception 'Swift_TransportException' with message 'Expected response code 250 but got code "553", with message "553 5.7.1 Sender address rejected: not owned by auth user.\r\n"'
A can't understand why do I need "From" field if the message is sent from the site?? The person just fills up the form and I wnat to get an email with the data he or she filled in? What should I write in the "From" field?
UPD: Finally emails are sent!!! Just made 'From' and 'To' email addresses equal
Thanks to all of you for help
Looks like you are missing a closing double quote on this line:
$message = "Name:$name::::::::::Email:$email::::::::::Phone No:$phone:::::::::;
Should be:
$message = "Name:$name::::::::::Email:$email::::::::::Phone No:$phone:::::::::;";
Also, you shouldn't have posted your mail account information. It's time to change your account's password.
Check this. Your using The SMTP server of smtp.yandex.ru
$transport = Swift_SmtpTransport::newInstance('smtp.yandex.ru', 465, 'ssl')
And the sender address is from gmail
->setFrom(array('kirabidzu#gmail.com' => 'PlayPad 2 Kids tablet order'))
There are servers that check that the sender address correspond to a really user. And this looks like your problem. To solve the error I think that you have two options.
a) you can set the smtp of gmail:
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl');
b) take a really sender address of yandex.ru
I hoope that this help you.
Based on the Joomla! documentation # http://docs.joomla.org/Sending_email_from_extensions, I'm trying to send emails with the code below:
function sendmail($file,$mailto)
{
$mailer =& JFactory::getMailer();
//var_dump($mailer); exit;
$config =&JFactory::getConfig();
$sender = array(
$config->getValue( 'config.mailfrom' ),
$config->getValue( 'config.fromname' )
);
$mailer->setSender($sender);
$recipient = array($mailto);
$mailer->addRecipient($recipient);
$body = "Your body string\nin double quotes if you want to parse the \nnewlines etc";
$mailer->setSubject('Your subject string');
$mailer->setBody($body);
// Optional file attached
$mailer->addAttachment(JPATH_BASE.DS.'CSV'.DS.$file);
$send =&$mailer->Send();
if ( $send !== true ) {
echo 'Error sending email: ' . $send->message;
} else {
echo 'Mail sent';
}
}
($file is the full path of a file zip and $mailto is a my gmail.)
However, when I send mail, I receive the error:
Could not instantiate mail function.
Fatal error: Cannot access protected property JException::$message in /var/www/html/dai/components/com_servicemanager/views/i0602/view.html.php on line 142
What is causing this error?
Please save yourself some sanity and do not try to use Joomla's mailer implementation. Not only is it unreliable as you've experienced, it handles different charsets and HTML content poorly. Just include and use PHPMailer.
Change
echo 'Error sending email: ' . $send->message;
to
echo 'Error sending email:'.$send->get('message');
then run your code again. The error that you get should tell us why it isn't instantiating.
In joomla send a mail with attachment file
$from="noreplay#gmail.com";//Please set Proper email id
$fromname="noreplay";
$to ='admin#gmail.com';
// Set a you want send email to
$subject = "Download";
$message = "Thank you For Downloading";
$attachment = JPATH_BASE.'/media/demo.pdf';
// set a file path
$res = JFactory::getMailer()->sendMail($from, $fromname, $to,$subject, $message,$mode=1,$cc = null, $bcc = null, $attachment);
if($res)
{
$errormsg = "Mail Successfully Send";
}
else
{
$errormsg ="Mail Not Send";
}
after you have check mail in your inbox or spam folder.
mail in spam folder because not proper set email id in from id.
After several years of Joomla development, I recommend using RSFORM PRO by RSJOOMLA to send mail for you after the visitor to your website fills out the form. It is much easier to manage than having to deal with the internal mail server.