I want to write a simple Drupal7 module, which contains following codes, used to send mail. Don't ask me to use Phpmailer or others. Could you help? Thanks very much!
<?php
include('Mail.php');
$recipients = array( 'someone#example.com' ); # Can be one or more emails
$headers = array (
'From' => 'someone#example.com',
'To' => join(', ', $recipients),
'Subject' => 'Testing email from project web',
);
$body = "This was sent via php from project web!\n";
$mail_object =& Mail::factory('smtp',
array(
'host' => 'prwebmail',
'auth' => true,
'username' => 'YOUR_PROJECT_NAME',
'password' => 'PASSWORD', # As set on your project's config page
#'debug' => true, # uncomment to enable debugging
));
$mail_object->send($recipients, $headers, $body);
Related
I am trying to use send grid as an email platform for my php but the problem is I cannot send multiple emails as a CC header and also I cannot edit the FROM header to display a Name in front of the email address.
$from = "News Letter <new#gmail.com>" // cannot get the "News Letter" to Display
$cc = array("aaaaaa#gmail.com","bbbbb#gmail.com");// doesnt send to arrays
$params = array(
'api_user' => $user,
'api_key' => $pass,
'to' => $to,
'cc' => $cc,
'subject' => $subject,
'html' => $body,
'from' => $headers
);
You need to use some additional fields in your $params array, like so:
$params = array(
'api_user' => $user,
'api_key' => $pass,
'to' => $to,
'toname' => 'Newsletter Person',
'cc' => $cc,
'subject' => $subject,
'html' => $body,
'from' => $headers,
'fromname' => 'Newsletter'
);
Sendind directly via the Mail.Send endpoint does not allow for an array in the CC field, however if you use the SendGrid PHP library then you can use and array for CC
I want to send an email using zend/mail in zend framework 2.
I already have some code but i don't know where to put it, and also not how to trigger this.
$mail = new Mail\Message();
$mail->setBody('This is the text of the email.');
$mail->setFrom('email#hotmail.be', 'email');
$mail->addTo('email#hotmail.be', 'email');
$mail->setSubject('Dit is een email verzonden van de computer');
$transport = new Mail\Transport\Sendmail('-freturn_to_email#hotmail.be');
$transport->send($mail);
I still new at Zend framework 2.
Can anybody help me with this?
I would advice you to take a look at Soflomo\Mail. Note, I am the author of Soflomo mail, but it helps you a lot with sending mails. It eases the config and dependency hassle.
Put "soflomo/mail": "~0.3" in your composer.json file and run the following command:
php composer.phar update soflomo/mail
Next, enable the module Soflomo\Mail in your application.config.php. When you use Zend\Mvc, you will have a controller/action which should trigger the email. For the most simplified use case, you can do this:
public function doAction()
{
// some of your logic
$service = $this->getServiceLocator()->get('Soflomo\Mail\Service\MailService');
$service->send(array(
'to' => 'email#hotmail.be',
'to_name' => 'email',
'from' => 'email#hotmail.be',
'from_name' => 'email',
'subject' => 'Dit is een email verzonden van de computer',
'template' => 'mail/message/default'
));
}
Now Soflomo\Mail sends a message by rendering a template and use that as message text. Here I defined a message mail/message/default so create that file (e.g. module/Application/view/mail/message/default.phtml) with this content:
This is the text of the email.
The last thing to do is to configure how Soflomo/Mail sends the message. Your question uses Sendmail, so I am using this as well in this example. Create a configuration file in config/autoload , e.g. config/autoload/soflomo_mail.global.php which contains the following content:
return array(
'soflomo_mail' => array(
'transport' => array(
'type' => 'sendmail',
),
),
);
If you want to switch to e.g. GMail as transport layer, replace above config with:
return array(
'soflomo_mail' => array(
'transport' => array(
'type' => 'smtp',
'options' => array(
'name' => 'gmail.com',
'host' => 'smtp.gmail.com',
'port' => 587,
'connection_class' => 'login',
'connection_config' => array(
'ssl' => 'tls',
'username' => '%USERNAME%',
'password' => '%PASSWORD%',
),
),
'variables' => array(
'username' => '',
'password' => '',
),
),
),
);
And create a new file config/autoload/soflomo_mail.local.php:
return array(
'soflomo_mail' => array(
'transport' => array(
'variables' => array(
'username' => 'my-address#gmail.com',
'password' => '1234secure7890',
),
),
),
);
I guess Hotmail would be similar to GMail.
You can use this within the zend directory,
$mail = new Zend_Mail();
$mail->setBodyText('This is the text of the mail.');
$mail->setFrom('somebody#example.com', 'Some Sender');
$mail->addTo('somebody_else#example.com', 'Some Recipient');
$mail->setSubject('TestSubject');
$mail->send();
I'm trying to put a heart symbol ♥ into the headline of an email which should be sent via the php pear mail package.
But the receiver gets a ? instead of the heart so there has to be some mistake. It works if I manually send the email with my mail client.
My code is the following:
require_once "Mail.php";
$smtp = Mail::factory('smtp',
array ('host' => 'host',
'port' => port,
'auth' => true,
'username' => 'username',
'password' => 'password');
$headers = array ('From' => 'sender',
'Subject' => '♥ test',
'Charset' => 'utf-8',
);
$mail = $smtp->send($to, $headers, 'heart test');
What do I need to change in order to make the heart display correctly for the receiver of the email?
You're not specifying the character set properly, so yes... it is a charset mismatch:
$headers = array(
'Content-type' => 'text/plain; charset=UTF-8'
);
is what you should have. There is no Charset header.
I'm trying to send emails that will bounce to an address specified by me, different from the address it's sent from.
the code i'm using to send the emails is
$headers = array (
'From' => $emailAdr
'To' => $emailDest,
'Subject' => $subject,
);
$hdrs = $mime->headers($headers);
$smtp = Mail::factory('smtp',
array ('host' => 'ssl://'.$emailServer,
'auth' => true,
'port' => '465',
'username' => $emailUser,
'password' => $emailPass));
$mail = $smtp->send($emailDest, $hdrs, $body);
I searched all over the internet for a solution to this.
Try this:
$headers = array (
'From' => $emailAdr
'To' => $emailDest,
'Subject' => $subject,
'Return-path' => 'return#path.com',
);
But, different mail servers translate return path by their own rules (it's just will use From, Reply-to or X-Return-Path etc
hi friends how to send a email through kohana 3.0
i tried but not working
my code is like this
$subject = ' : Message to Leet Street';
$from = array('Clarence', 'ratnaraju.java#gmail.com');
email::send('ratnaraju.bonam#gmail.com', $from , $subject, 'hi how r u Brother ');
url::redirect();
config file is:
return array
(
'default' => array(
'transport' => 'smtp',
'options' => array
(
'hostname' => 'smtp.gmail.com',
'username' => 'ratnaraju.bonam#gmail.com',
'password' => 'Ratna',
'port' => '465',
),
)
);
thanks in advance
Use this module to send email:
https://github.com/shadowhand/email
it needs this vendor in the vendor-dir:
https://github.com/swiftmailer/swiftmailer