GithubHelp home page GithubHelp logo

mailer's Introduction

Mailer

A lightweight SMTP mail sender

Install

$ composer require txthinking/mailer
# or
$ composer require txthinking/mailer:dev-master

Usage

<?php
use Tx\Mailer;

$ok = (new Mailer())
    ->setServer('smtp.server.com', 25)
    ->setAuth('[email protected]', 'password')
    ->setFrom('Tom', '[email protected]')
    ->setFakeFrom('Obama', '[email protected]') // if u want, a fake name, a fake email
    ->addTo('Jerry', '[email protected]')
    ->setSubject('Hello')
    ->setBody('Hi, Jerry! I <strong>love</strong> you.')
    ->addAttachment('host', '/etc/hosts')
    ->send();
var_dump($ok);

More Example

mailer's People

Contributors

daemionfox avatar echosong avatar joshtronic avatar msowerserb avatar splitbrain avatar txthinking avatar vinkla avatar xylane avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mailer's Issues

Can't Reply to The Sender

Hello. I'm getting the email but whenever I try to reply, in the reply to field, I get "[email protected]".
Moreover, it doesn't show the sender email in the header, it shows the email I'm using in setAuth not '[email protected]'.
Please check the attached files.
Thanks in advance.
code
email

Remove Exceptions

I think much more exception class files is unnecessary.
If there is an error, only need to report human readable errors string.

When not adding "reply-to", reply-to header is populated with "<>"

Hello,

When using Mailer without mentioning the reply-to (like the example given in the main page), this header is anyway added to the e-mail with the value "<>", preventing you to reply to the e-mails received.
This header shouldn't exist if you didn't add it, and in this case the mail client will use the "from" field to reply.

Fix proposed (in Message.php, around line 350):

Replace:
$this->header['Reply-To'] = $replyToName . "<" . $this->replyToEmail . ">";

By:
if(!empty($this->replyToEmail)){ $this->header['Reply-To'] = $replyToName . "<" . $this->replyToEmail . ">"; }

Regards,

Xylane

Try to update smtp->connect() function to enable self-signed server certificates, disable peer (name) validation

I use your mailer within dokuwiki and the smtp-modul:

Some features were missing so i tried to update the SMTP->connect() function to enable support for

  • selbst signed ssl/tls server certificates
  • disable peer validation
  • disable peer name validation
    and other options, but currently it won't work - maybe someone has same problem like me (small DMZ-Mail server with self-signed certificate)
// \Mailer\src\Mailer\SMTP.php:196
protected function connect()
{
	$this->logger && $this->logger->debug("Connecting to {$this->host} at {$this->port}");
	/*
	$host = ($this->secure == 'ssl') ? 'ssl://' . $this->host : $this->host;
	$this->smtp = @fsockopen($host, $this->port);
	//set block mode
	//    stream_set_blocking($this->smtp, 1);
	*/
	switch ( $this->secure ) {
		case 'ssl' :
			$host = 'ssl://' . $this->host;
			break;
		case 'tls' :
			$host = 'tls://' . $this->host;
			break;
		default:
			$host = $this->host;
	}
	$hostport = $host.($this->port ? ':' . $this->port : '' );
	$socket_options = array(
		'ssl' => array(
			'verify_peer' => false,
			'verify_peer_name' => false,
			'allow_self_signed' => true,
		)
	);
	$socket_context = stream_context_create($socket_options);
	$errno = '';
	$errstr = '';
	$this->smtp = stream_socket_client($hostport, $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $socket_context);
	if (!$this->smtp){
		//throw new SMTPException("Could not open SMTP Port.");
		throw new SMTPException("Could not open SMTP Host/Port: ".$hostport.". Error:" . $errno . " - " . $errstr . ', '. var_export ( $socket_context, true) . ', ' . var_export($this->smtp, true) );
	}
	$code = $this->getCode();
	if ($code !== '220'){
		throw new CodeException('220', $code, array_pop($this->resultStack));
	}
	return $this;
}

i get the following error:

There was an unexpected problem communicating with SMTP: Could not open SMTP Host/Port: tls://:Error:0 - , NULL, false

Documentation stream_socket_client:

If the value returned in error_code is 0 and the function returned false, it is an indication that the error occurred before the connect() call. This is most likely due to a problem initializing the socket.

But i don't know - if i use openssl-cli the connection might no problem:

openssl s_client -connect <myhost>:<post> -starttls smtp

Can anyone help?
Thx!

setX and addX act on array

Message: setTo Before #14, effect same as addTo, and the commit message is too simple, just a cli, that is not easy to understand intension.
Message: addTo
Message: addCc
Message: addBcc
Message: setAttachment
Message: addAttachment

Mailer: setTo I think If change Message: setTo effect, MUST change Mailer: setTo too
Mailer: addTo
Mailer: addCc
Mailer: addBcc
Mailer: setAttachment
Mailer: addAttachment

If we define, this makes it easy to understand why has both add and set:

  • setX: empty array and append a new item
  • addX: append a new item

We should:

  • MUST: modify Message: setAttachment to empty array and append a new item
  • MAYBE: add Message: setCc
  • MAYBE: add Message: setBcc
  • MAYBE: add Message: setBcc
  • MUST: make same effect Message:X and Mailer:X

Sending emails

I setup install all by composer but when I try to sent email I get all time errors:

My code is:
`<?php
require DIR . '/vendor/autoload.php';

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

use \Tx\Mailer;

$ok = (new Mailer())
->setServer('poczta.o2.pl', '465')
->setAuth('[email protected]', 'PASSWORD')
->setFrom('Andrej', '[email protected]')
//->setFakeFrom('Obama', '[email protected]') // if u want, a fake name, a fake email
->addTo('KnicatBakery', '[email protected]')
->setSubject('Hello')
->setBody('Hi, Jerry! I love you.')
//->addAttachment('host', '/etc/hosts')
->send();
var_dump($ok);
`

and get reply:
Fatal error: Uncaught Tx\Mailer\Exceptions\SMTPException: SMTP Server did not respond with anything I recognized in /smtp/vendor/txthinking/mailer/src/Mailer/SMTP.php:459 Stack trace: #0 /smtp/vendor/txthinking/mailer/src/Mailer/SMTP.php(206): Tx\Mailer\SMTP->getCode() #1 /smtp/vendor/txthinking/mailer/src/Mailer/SMTP.php(169): Tx\Mailer\SMTP->connect() #2 /smtp/vendor/txthinking/mailer/src/Mailer.php(193): Tx\Mailer\SMTP->send() #3 /smtp/index.php(21): Tx\Mailer->send() #4 {main} thrown in /smtp/vendor/txthinking/mailer/src/Mailer/SMTP.php on line 459

When I setup all for gmail account I get diffrent error:

I change only settings:
$ok = (new Mailer()) ->setServer('smtp.gmail.com', '25') ->setAuth('[email protected]', 'PASSWORD') ->setFrom('DJ', '[email protected]') //->setFakeFrom('Obama', '[email protected]') // if u want, a fake name, a fake email ->addTo('KnicatBakery', '[email protected]') ->setSubject('Hello') ->setBody('Hi, Jerry! I <strong>love</strong> you.') //->addAttachment('host', '/etc/hosts') ->send(); var_dump($ok);

Reply:

Fatal error: Uncaught Tx\Mailer\Exceptions\CodeException: Unexpected return code - Expected: 334, Got: 530 | 530 5.7.0 Must issue a STARTTLS command first. s11sm786228lfr.290 - gsmtp in /smtp/vendor/txthinking/mailer/src/Mailer/SMTP.php:285 Stack trace: #0 /smtp/vendor/txthinking/mailer/src/Mailer/SMTP.php(178): Tx\Mailer\SMTP->authLogin() #1 /smtp/vendor/txthinking/mailer/src/Mailer.php(193): Tx\Mailer\SMTP->send() #2 /smtp/index.php(21): Tx\Mailer->send() #3 {main} thrown in /smtp/vendor/txthinking/mailer/src/Mailer/SMTP.php on line 285

I tried also to change:
->setServer('smtp.gmail.com', '465') and ->setServer('smtp.gmail.com', '587')

but for 465 I get same error:
Fatal error: Uncaught Tx\Mailer\Exceptions\SMTPException: SMTP Server did not respond with anything I recognized in /smtp/vendor/txthinking/mailer/src/Mailer/SMTP.php:459 Stack trace: #0 /smtp/vendor/txthinking/mailer/src/Mailer/SMTP.php(206): Tx\Mailer\SMTP->getCode() #1 /smtp/vendor/txthinking/mailer/src/Mailer/SMTP.php(169): Tx\Mailer\SMTP->connect() #2 /smtp/vendor/txthinking/mailer/src/Mailer.php(193): Tx\Mailer\SMTP->send() #3 /smtp/index.php(21): Tx\Mailer->send() #4 {main} thrown in /smtp/vendor/txthinking/mailer/src/Mailer/SMTP.php on line 459

for 587:
Fatal error: Uncaught Tx\Mailer\Exceptions\SMTPException: SMTP Server did not respond with anything I recognized in /smtp/vendor/txthinking/mailer/src/Mailer/SMTP.php:459 Stack trace: #0 /smtp/vendor/txthinking/mailer/src/Mailer/SMTP.php(206): Tx\Mailer\SMTP->getCode() #1 /smtp/vendor/txthinking/mailer/src/Mailer/SMTP.php(169): Tx\Mailer\SMTP->connect() #2 /smtp/vendor/txthinking/mailer/src/Mailer.php(193): Tx\Mailer\SMTP->send() #3 /smtp/index.php(21): Tx\Mailer->send() #4 {main} thrown in /smtp/vendor/txthinking/mailer/src/Mailer/SMTP.php on line 459

Any advice please how to setup it?

DKIM Support

Been trying to get DKIM support added into the mailer, but nothing I'm doing seems to work. @txthinking do you have any thoughts adding this?

Installation issues

Hi, I installed it by composer command but it don't work at all.
I made index.php and input value which is in section as example but always I get error:

Fatal error: Uncaught Error: Class "Tx\Mailer" not found in /smtp-mailer/vendor/index.php:8 Stack trace: #0 {main} thrown in /smtp-mailer/vendor/index.php on line 8

no matter where I place index.php, I tested in every folder

Can anyone advice me something?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.