Skip to content

Instantly share code, notes, and snippets.

@tamouse
Created November 16, 2012 08:15
Show Gist options
  • Select an option

  • Save tamouse/4085385 to your computer and use it in GitHub Desktop.

Select an option

Save tamouse/4085385 to your computer and use it in GitHub Desktop.
testing PEAR::Mail with and without recipient
Recipient = joe@example.com
DEBUG: Recv: 220 omta07.emeryville.ca.mail.comcast.net comcast ESMTP server ready
DEBUG: Send: EHLO localhost
DEBUG: Recv: 250-omta07.emeryville.ca.mail.comcast.net hello [71.63.215.130], pleased to meet you
DEBUG: Recv: 250-HELP
DEBUG: Recv: 250-AUTH LOGIN PLAIN
DEBUG: Recv: 250-SIZE 36700160
DEBUG: Recv: 250-ENHANCEDSTATUSCODES
DEBUG: Recv: 250-8BITMIME
DEBUG: Recv: 250-STARTTLS
DEBUG: Recv: 250 OK
DEBUG: Send: STARTTLS
DEBUG: Recv: 220 2.0.0 Ready to start TLS
DEBUG: Send: EHLO localhost
DEBUG: Recv: 250-omta07.emeryville.ca.mail.comcast.net hello [71.63.215.130], pleased to meet you
DEBUG: Recv: 250-HELP
DEBUG: Recv: 250-AUTH LOGIN PLAIN
DEBUG: Recv: 250-SIZE 36700160
DEBUG: Recv: 250-ENHANCEDSTATUSCODES
DEBUG: Recv: 250-8BITMIME
DEBUG: Recv: 250 OK
DEBUG: Send: AUTH LOGIN
DEBUG: Recv: 334 VXNlcm5hbWU6
DEBUG: Send: dGFtb3VzZQ==
DEBUG: Recv: 334 UGFzc3dvcmQ6
DEBUG: Send: TjF0d29vZEA5
DEBUG: Recv: 235 2.7.0 ... Authentication succeeded
DEBUG: Send: MAIL FROM:<tamara@tamaratemple.com>
DEBUG: Recv: 250 2.1.0 <tamara@tamaratemple.com> sender ok
DEBUG: Send: RCPT TO:<joe@example.com>
DEBUG: Recv: 250 2.1.5 <joe@example.com> recipient ok
DEBUG: Send: DATA
DEBUG: Recv: 354 enter mail, end with "." on a line by itself
DEBUG: Send: From: tamara@tamaratemple.com
To: joe@example.com
Subject: Test message
Test message
DEBUG: Send:
.
DEBUG: Recv: 250 2.0.0 Q8Dx1k00A2pNiMz8U8DyzJ mail accepted for delivery
DEBUG: Send: QUIT
DEBUG: Recv: 221 2.0.0 omta07.emeryville.ca.mail.comcast.net comcast closing connection
Recipient =
DEBUG: Recv: 220 omta16.emeryville.ca.mail.comcast.net comcast ESMTP server ready
DEBUG: Send: EHLO localhost
DEBUG: Recv: 250-omta16.emeryville.ca.mail.comcast.net hello [71.63.215.130], pleased to meet you
DEBUG: Recv: 250-HELP
DEBUG: Recv: 250-AUTH LOGIN PLAIN
DEBUG: Recv: 250-SIZE 36700160
DEBUG: Recv: 250-ENHANCEDSTATUSCODES
DEBUG: Recv: 250-8BITMIME
DEBUG: Recv: 250-STARTTLS
DEBUG: Recv: 250 OK
DEBUG: Send: STARTTLS
DEBUG: Recv: 220 2.0.0 Ready to start TLS
DEBUG: Send: EHLO localhost
DEBUG: Recv: 250-omta16.emeryville.ca.mail.comcast.net hello [71.63.215.130], pleased to meet you
DEBUG: Recv: 250-HELP
DEBUG: Recv: 250-AUTH LOGIN PLAIN
DEBUG: Recv: 250-SIZE 36700160
DEBUG: Recv: 250-ENHANCEDSTATUSCODES
DEBUG: Recv: 250-8BITMIME
DEBUG: Recv: 250 OK
DEBUG: Send: AUTH LOGIN
DEBUG: Recv: 334 VXNlcm5hbWU6
DEBUG: Send: dGFtb3VzZQ==
DEBUG: Recv: 334 UGFzc3dvcmQ6
DEBUG: Send: TjF0d29vZEA5
DEBUG: Recv: 235 2.7.0 ... Authentication succeeded
DEBUG: Send: MAIL FROM:<tamara@tamaratemple.com>
DEBUG: Recv: 250 2.1.0 <tamara@tamaratemple.com> sender ok
DEBUG: Send: RCPT TO:<@localhost>
DEBUG: Recv: 550 5.5.0 <@localhost> invalid address
DEBUG: Send: RSET
DEBUG: Recv: 250 2.0.0 OK
PEAR SMTP Send error: Failed to add recipient: @localhost [SMTP: Invalid response code received from server (code: 550, response: 5.5.0 <@localhost> invalid address)]
Mail object: [pear_error: message="Failed to add recipient: @localhost [SMTP: Invalid response code received from server (code: 550, response: 5.5.0 <@localhost> invalid address)]" code=10005 mode=return level=notice prefix="" info=""]
Mail debug info:
testmail.php failed
DEBUG: Send: QUIT
DEBUG: Recv: 221 2.0.0 omta16.emeryville.ca.mail.comcast.net comcast closing connection
<?php // -*- mode: php; time-stamp-start: "version [\"<]"; time-stamp-format: "%Y-%3b-%02d %02H:%02M"; -*-
/**
*
* testmail
*
* @author Tamara Temple <tamara@tamaratemple.com>
* @since 2012-11-14
* @version <2012-Nov-16 02:07>
* @copyright (c) 2012 Tamara Temple Web Development
* @license GPLv3
*
*/
require_once 'Mail.php';
header('Content-type: text/plain;');
$recipient = $argv[1]; // first argument is email address of recipient
printf("Recipient = %s\n", $recipient);
$headers['From'] = 'tamara@tamaratemple.com';
$headers['To'] = $recipient;
$headers['Subject'] = 'Test message';
$body = 'Test message';
$creds = yaml_parse_file(".smtpcreds.yaml");
$smtp = Mail::factory('smtp',
array ('host' => $creds['host'],
'auth' => true,
'port' => $creds['port'],
'debug' => true,
'username' => $creds['username'],
'password' => $creds['password']));
if (PEAR::isError($smtp)) {
printf("PEAR Mail Factory error: %s\n", $smtp->getMessage());
printf("SMTP Object: %s\n", $smtp->toString());
printf("SMTP Debug info: %s\n", $smtp->getDebugInfo());
die("\n\ttestmail.php failed\n\n");
}
$mail = $smtp->send($recipient, $headers, $body);
if (PEAR::isError($mail)) {
printf("PEAR SMTP Send error: %s\n", $mail->getMessage());
printf("Mail object: %s\n", $mail->toString());
printf("Mail debug info: %s\n", $mail->getDebugInfo());
die("\n\ttestmail.php failed\n\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment