This question already has answers here:
Sending email with PHP from an SMTP server
(9 answers)
Closed 4 years ago.
I have an Android HTML5 php application where I want to enable users to send emails to other people by using Gmail or Yahoo. This is the code that I use
<?php
$smtp=$_GET["smtp"];
$youremail= $_GET["youremail"];
$emailpassword=$_GET["emailpassword"];
$companyemail=$_GET["companyemail"];
$messagetitle= $_GET["messagetitle"];
$messagetext=$_GET["messagetext"];
//this is a path to PHP mailer class you have dowloaded
include("class.phpmailer.php");
$emailChunks = explode(",", $companyemail);
for($i = 0; $i < count($emailChunks); $i++){
// echo "Piece $i = <br />";
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1; // errors and messages
//$mail->SMTPSecure = "tls"; // sets the prefix to the servier
$mail->Port = 587;
$mail->Host = "$smtp";
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "$youremail"; // SMTP username
$mail->Password = "$emailpassword"; // SMTP password
$mail->From = "$youremail"; //do NOT fake header.
$mail->FromName = "$youremail";
$mail->AddAddress("$emailChunks[$i]"); // Email on which you want to send mail
$mail->AddReplyTo("$emailpassword", "Reply to"); //optional
$mail->IsHTML(true);
$mail->Subject = "$messagetitle";
$mail->Body = "$messagetext";
if(!$mail->Send())
{
echo $mail->ErrorInfo;
}else{
echo "email was sent";
}
}
?>
Error that i get is:
Invalid address: mysmtppassxxxxSMTP -> ERROR: Failed to connect to server: Connection timed out (110)
SMTP Error: Could not connect to SMTP host.
SMTP Error: Could not connect to SMTP host
when I do a var_dump($email) I get
object(PHPMailer)#1 (53) {
["Priority"]=>
int(3)
["CharSet"]=>
string(10) "iso-8859-1"
["ContentType"]=>
string(9) "text/html"
["Encoding"]=>
string(4) "8bit"
["ErrorInfo"]=>
string(0) ""
["From"]=>
string(18) "me#gmail.com"
["FromName"]=>
string(18) "me#gmail.com"
["Sender"]=>
string(0) ""
["Subject"]=>
string(4) "test"
["Body"]=>
string(10) "my message"
["AltBody"]=>
string(0) ""
["WordWrap"]=>
int(0)
["Mailer"]=>
string(4) "smtp"
["Sendmail"]=>
string(18) "/usr/sbin/sendmail"
["PluginDir"]=>
string(0) ""
["ConfirmReadingTo"]=>
string(0) ""
["Hostname"]=>
string(0) ""
["MessageID"]=>
string(0) ""
["Host"]=>
string(14) "smtp.gmail.com"
["Port"]=>
int(587)
["Helo"]=>
string(0) ""
["SMTPSecure"]=>
string(3) "ssl"
["SMTPAuth"]=>
bool(true)
["Username"]=>
string(18) "me#gmail.com"
["Password"]=>
string(18) "me#gmail.com"
["Timeout"]=>
int(10)
["SMTPDebug"]=>
int(1)
["SMTPKeepAlive"]=>
bool(false)
["SingleTo"]=>
bool(false)
["SingleToArray"]=>
array(0) {
}
["LE"]=>
string(1) "
"
["DKIM_selector"]=>
string(9) "phpmailer"
["DKIM_identity"]=>
string(0) ""
["DKIM_domain"]=>
string(0) ""
["DKIM_private"]=>
string(0) ""
["action_function"]=>
string(0) ""
["Version"]=>
string(3) "5.1"
["smtp:private"]=>
NULL
["to:private"]=>
array(1) {
[0]=>
array(2) {
[0]=>
string(18) "jvkrneta#yahoo.com"
[1]=>
string(0) ""
}
}
["cc:private"]=>
array(0) {
}
["bcc:private"]=>
array(0) {
}
["ReplyTo:private"]=>
array(1) {
["me#gmail.com"]=>
array(2) {
[0]=>
string(18) "me#gmail.com"
[1]=>
string(8) "Reply to"
}
}
["all_recipients:private"]=>
array(1) {
["joovkrneta#yahoo.com"]=>
bool(true)
}
["attachment:private"]=>
array(0) {
}
["CustomHeader:private"]=>
array(0) {
}
["message_type:private"]=>
string(0) ""
["boundary:private"]=>
array(0) {
}
["language:protected"]=>
array(0) {
}
["error_count:private"]=>
int(0)
["sign_cert_file:private"]=>
string(0) ""
["sign_key_file:private"]=>
string(0) ""
["sign_key_pass:private"]=>
string(0) ""
["exceptions:private"]=>
bool(false)
}
The $mail->AddAddress() section has invalid syntax.
Change it from $mail->AddAddress("$emailChunks[$i]"); to $mail->AddAddress("${emailChunks[$i]}");
Basically, the parser doesn't recognize that the subscript isn't part of the string.
This article explains it in more depth: Can I subscript an array variable inside a double quoted PHP string?
Related
I'm using FedEx web services and jeremy-dunn/php-fedex-api-wrapper and attempting to have FedEx send me a plaintext email notification when a package has been delivered. I am using a third party for order fulfillment, and they have and use a different FedEx account that is not mine. (Maybe this is the problem?)
I can track the packages just fine, and when I attempt to subscribe to the delivery notification, the response from FedEx seems to indicate success. I am in testing mode. I'm NOT currently in production mode, in case that matters.
My request uses the following function:
function fedexWebServicesNotificationSubscription( $trackingNumber, $recipient, $sender )
{
global $fedexApiMode;
if( ! is_array( $recipient ) OR ! isset( $recipient['email_addr'] ) )
return FALSE;
if( ! is_array( $sender ) OR ! isset( $sender['email_addr'], $sender['name'] ) )
return FALSE;
$userCredential = new ComplexType\WebAuthenticationCredential();
$userCredential->setKey(FEDEX_KEY)
->setPassword(FEDEX_PASSWORD);
$webAuthenticationDetail = new ComplexType\WebAuthenticationDetail();
$webAuthenticationDetail->setUserCredential($userCredential);
$clientDetail = new ComplexType\ClientDetail();
$clientDetail->setAccountNumber(FEDEX_ACCOUNT_NUMBER)
->setMeterNumber(FEDEX_METER_NUMBER);
$version = new ComplexType\VersionId();
$version->setMajor(5)
->setIntermediate(0)
->setMinor(0)
->setServiceId('trck');
$localization = new ComplexType\Localization();
$localization->setLocaleCode("US")
->setLanguageCode("EN");
$emailRecip = new ComplexType\EMailNotificationRecipient();
$emailRecip->setEMailNotificationRecipientType(SimpleType\EMailNotificationRecipientType::_SHIPPER)
->setEMailAddress( $recipient['email_addr'] )
->setLocalization($localization)
->setFormat(SimpleType\EMailNotificationFormatType::_TEXT)
->setNotificationEventsRequested([
SimpleType\EMailNotificationEventType::_ON_DELIVERY,
SimpleType\EMailNotificationEventType::_ON_EXCEPTION,
SimpleType\EMailNotificationEventType::_ON_SHIPMENT,
SimpleType\EMailNotificationEventType::_ON_TENDER
]);
$emailNotificationDetail = new ComplexType\EMailNotificationDetail();
$emailNotificationDetail->setPersonalMessage('Shipment Status Notification')
->setRecipients([$emailRecip]);
$request = new ComplexType\TrackNotificationRequest();
$request->setWebAuthenticationDetail($webAuthenticationDetail)
->setClientDetail($clientDetail)
->setVersion($version)
->setTrackingNumber( $trackingNumber )
->setSenderEMailAddress( $sender['email_addr'] )
->setSenderContactName( $sender['name'] )
->setNotificationDetail($emailNotificationDetail);
$trackServiceRequest = new TrackService\Request();
if( $fedexApiMode == 'production' )
$trackServiceRequest->getSoapClient()->__setLocation(TrackService\Request::PRODUCTION_URL);
$response = $trackServiceRequest->getGetTrackNotificationReply($request, TRUE);
return $response;
}
I use that function like this:
$trackingNumber = '781893213291';
$recipient = [
'email_addr' => 'email#example.com'
];
$sender = [
'email_addr' => 'email#example.com',
'name' => 'My Name'
];
$response = fedexWebServicesNotificationSubscription( $trackingNumber, $recipient, $sender );
echo '<pre>';
var_dump($response);
echo '</pre>';
And my response looks like this:
object(stdClass)#28 (6) {
["HighestSeverity"]=>
string(7) "SUCCESS"
["Notifications"]=>
object(stdClass)#29 (5) {
["Severity"]=>
string(7) "SUCCESS"
["Source"]=>
string(4) "trck"
["Code"]=>
string(1) "0"
["Message"]=>
string(35) "Request was successfully processed."
["LocalizedMessage"]=>
string(35) "Request was successfully processed."
}
["Version"]=>
object(stdClass)#30 (4) {
["ServiceId"]=>
string(4) "trck"
["Major"]=>
int(5)
["Intermediate"]=>
int(0)
["Minor"]=>
int(0)
}
["DuplicateWaybill"]=>
bool(false)
["MoreDataAvailable"]=>
bool(false)
["Packages"]=>
object(stdClass)#31 (6) {
["TrackingNumber"]=>
string(12) "781893213291"
["TrackingNumberUniqueIdentifiers"]=>
string(23) "12018~781893213291~FDEG"
["CarrierCode"]=>
string(4) "FDXG"
["ShipDate"]=>
string(10) "2018-07-17"
["Destination"]=>
object(stdClass)#32 (4) {
["City"]=>
string(13) "SAN FRANCISCO"
["StateOrProvinceCode"]=>
string(2) "CA"
["CountryCode"]=>
string(2) "US"
["Residential"]=>
bool(false)
}
["RecipientDetails"]=>
object(stdClass)#33 (1) {
["NotificationEventsAvailable"]=>
array(6) {
[0]=>
string(11) "ON_DELIVERY"
[1]=>
string(12) "ON_EXCEPTION"
[2]=>
string(12) "ON_EXCEPTION"
[3]=>
string(12) "ON_EXCEPTION"
[4]=>
string(12) "ON_EXCEPTION"
[5]=>
string(12) "ON_EXCEPTION"
}
}
}
}
So it appears that I have subscribed, and that I should receive an email notification when the package is delivered, but the email never arrives. So I need help to know what's wrong with my code, or what's wrong with what I'm doing. I believe I understand what I'm doing, but no success.
https://www.fedex.com/us/developer/WebHelp/ws/2014/dvg/WS_DVG_WebHelp/26_Shipment_Notification_in_the_Ship_Request.htm
Here it says you cannot receive an email in test enviro
1) In test mode, notifications are not sent. With the production key (production mode), notifications are sent. This is what I was expecting.
2) My code and the response I am getting back are fine.
3) Adding a track notification for a package that was not sent through my account works just fine. There is no restriction to adding track notifications, other than there may only be a total of 4.
Hello fellow developers,
Im currently trying to read all emails with imap. Im trying to get the header infos with imap_headerinfo and the body with imap_fetchbody.
However, I get all the headerinfo but I only get an empty string as a return from the fetchbody function. I hope someone can help me
$this->inbox = imap_open($server, $user, $password);
// Header und Body der Email auslesen
$emails = imap_search($this->inbox,'ALL');
foreach($emails as $k) {
$this->email_contents[$k] = array(
'header' => imap_headerinfo($this->inbox, $k),
'body' => imap_fetchbody($this->inbox, $k, '1')
);
}
imap_close($this->inbox);
fetch_structure
object(stdClass)#65 (11) {
["type"]=>
int(1)
["encoding"]=>
int(0)
["ifsubtype"]=>
int(1)
["subtype"]=>
string(5) "MIXED"
["ifdescription"]=>
int(0)
["ifid"]=>
int(0)
["ifdisposition"]=>
int(0)
["ifdparameters"]=>
int(0)
["ifparameters"]=>
int(1)
["parameters"]=>
array(1) {
[0]=>
object(stdClass)#66 (2) {
["attribute"]=>
string(8) "boundary"
["value"]=>
string(36) "------------CC4C1146391EA6C129642420"
}
}
["parts"]=>
array(2) {
[0]=>
object(stdClass)#67 (12) {
["type"]=>
int(0)
["encoding"]=>
int(1)
["ifsubtype"]=>
int(1)
["subtype"]=>
string(5) "PLAIN"
["ifdescription"]=>
int(0)
["ifid"]=>
int(0)
["lines"]=>
int(30)
["bytes"]=>
int(590)
["ifdisposition"]=>
int(0)
["ifdparameters"]=>
int(0)
["ifparameters"]=>
int(1)
["parameters"]=>
array(2) {
[0]=>
object(stdClass)#68 (2) {
["attribute"]=>
string(7) "charset"
["value"]=>
string(5) "utf-8"
}
[1]=>
object(stdClass)#69 (2) {
["attribute"]=>
string(6) "format"
["value"]=>
string(6) "flowed"
}
}
}
[1]=>
object(stdClass)#70 (13) {
["type"]=>
int(5)
["encoding"]=>
int(3)
["ifsubtype"]=>
int(1)
["subtype"]=>
string(4) "JPEG"
["ifdescription"]=>
int(0)
["ifid"]=>
int(0)
["bytes"]=>
int(1036)
["ifdisposition"]=>
int(1)
["disposition"]=>
string(10) "attachment"
["ifdparameters"]=>
int(1)
["dparameters"]=>
array(1) {
[0]=>
object(stdClass)#71 (2) {
["attribute"]=>
string(8) "filename"
["value"]=>
string(11) "logo_sm.jpg"
}
}
["ifparameters"]=>
int(1)
["parameters"]=>
array(1) {
[0]=>
object(stdClass)#72 (2) {
["attribute"]=>
string(4) "name"
["value"]=>
string(11) "logo_sm.jpg"
}
}
}
}
}
imap-fetchbody() works unusually when handling attached email messages and it's behaviour is inconsistent.
I was going to re-write this but to be honest the author atamido does a fantastic job of showing why this happens so i'll humbly cite his lead comment from this:: http://php.net/manual/en/function.imap-fetchbody.php he also includes an example of how to extract the body
imap-fetchbody() will decode attached email messages inline with the
rest of the email parts, however the way it works when handling
attached email messages is inconsistent with the main email message.
With an email message that only has a text body and does not have any mime attachments, imap-fetchbody() will return the following
for each requested part number:
(empty) - Entire message
0 - Message header
1 - Body text
With an email message that is a multi-part message in MIME format, and contains the message text in plain text and HTML, and has
a file.ext attachment, imap-fetchbody() will return something like the
following for each requested part number:
(empty) - Entire message
0 - Message header
1 - MULTIPART/ALTERNATIVE
1.1 - TEXT/PLAIN
1.2 - TEXT/HTML
2 - file.ext
Now if you attach the above email to an email with the message text in plain text and HTML, imap_fetchbody() will use this type of
part number system:
(empty) - Entire message
0 - Message header
1 - MULTIPART/ALTERNATIVE
1.1 - TEXT/PLAIN
1.2 - TEXT/HTML
2 - MESSAGE/RFC822 (entire attached message)
2.0 - Attached message header
2.1 - TEXT/PLAIN
2.2 - TEXT/HTML
2.3 - file.ext
Note that the file.ext is on the same level now as the plain text and
HTML, and that there is no way to access the MULTIPART/ALTERNATIVE in
the attached message.
Here is a modified version of some of the code from previous posts
that will build an easily accessible array that includes accessible
attached message parts and the message body if there aren't multipart
mimes. The $structure variable is the output of the
imap_fetchstructure() function. The returned $part_array has the
field 'part_number' which contains the part number to be fed directly
into the imap_fetchbody() function.
<?php
function create_part_array($structure, $prefix="") {
//print_r($structure);
if (sizeof($structure->parts) > 0) { // There some sub parts
foreach ($structure->parts as $count => $part) {
add_part_to_array($part, $prefix.($count+1), $part_array);
}
}else{ // Email does not have a seperate mime attachment for text
$part_array[] = array('part_number' => $prefix.'1', 'part_object' => $obj);
}
return $part_array;
}
// Sub function for create_part_array(). Only called by create_part_array() and itself.
function add_part_to_array($obj, $partno, & $part_array) {
$part_array[] = array('part_number' => $partno, 'part_object' => $obj);
if ($obj->type == 2) { // Check to see if the part is an attached email message, as in the RFC-822 type
//print_r($obj);
if (sizeof($obj->parts) > 0) { // Check to see if the email has parts
foreach ($obj->parts as $count => $part) {
// Iterate here again to compensate for the broken way that imap_fetchbody() handles attachments
if (sizeof($part->parts) > 0) {
foreach ($part->parts as $count2 => $part2) {
add_part_to_array($part2, $partno.".".($count2+1), $part_array);
}
}else{ // Attached email does not have a seperate mime attachment for text
$part_array[] = array('part_number' => $partno.'.'.($count+1), 'part_object' => $obj);
}
}
}else{ // Not sure if this is possible
$part_array[] = array('part_number' => $prefix.'.1', 'part_object' => $obj);
}
}else{ // If there are more sub-parts, expand them out.
if (sizeof($obj->parts) > 0) {
foreach ($obj->parts as $count => $p) {
add_part_to_array($p, $partno.".".($count+1), $part_array);
}
}
}
}
?>
I have contact form 7 in my website and I am using WP-SMTP plugin to send form data to my gmail account.
I have followed all the steps mentioned in the plugin.
and in Functions.php I have added the following code.
/*Send email*/
add_action( 'phpmailer_init', 'my_phpmailer_init' );
function my_phpmailer_init( PHPMailer $phpmailer ) {
$phpmailer->Host = 'smtp.gmail.net';
$phpmailer->Port = 465; // could be different
$phpmailer->Username = 'alisda.residency#gmail.com'; // if required
$phpmailer->Password = *******; // if required
$phpmailer->SMTPAuth = true; // if required
$phpmailer->SMTPSecure = 'ssl'; // enable if required, 'tls' is another possible value
$phpmailer->IsSMTP();
}
but I receive the following error
Test Message Sent
The result was:
bool(false)
The full debugging output is shown below:
object(PHPMailer)#1551 (76) {
["Version"]=>
string(6) "5.2.22"
["Priority"]=>
NULL
["CharSet"]=>
string(5) "UTF-8"
["ContentType"]=>
string(10) "text/plain"
["Encoding"]=>
string(4) "7bit"
["ErrorInfo"]=>
string(82) "SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting"
["From"]=>
string(26) "alisda.residency#gmail.com"
["FromName"]=>
string(9) "My Alisda"
["Sender"]=>
string(0) ""
["ReturnPath"]=>
string(0) ""
["Subject"]=>
string(50) "WP Mail SMTP: Test mail to shivanand3939#gmail.com"
["Body"]=>
string(68) "This is a test email generated by the WP Mail SMTP WordPress plugin."
["AltBody"]=>
string(0) ""
["Ical"]=>
string(0) ""
["MIMEBody":protected]=>
string(69) "This is a test email generated by the WP Mail SMTP WordPress plugin.
"
["MIMEHeader":protected]=>
string(369) "Date: Fri, 27 Jan 2017 05:13:00 +0000
To: shivanand3939#gmail.com
From: My Alisda
Subject: WP Mail SMTP: Test mail to shivanand3939#gmail.com
Message-ID:
X-Mailer: PHPMailer 5.2.22 (https://github.com/PHPMailer/PHPMailer)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
"
["mailHeader":protected]=>
string(0) ""
["WordWrap"]=>
int(0)
["Mailer"]=>
string(4) "smtp"
["Sendmail"]=>
string(18) "/usr/sbin/sendmail"
["UseSendmailOptions"]=>
bool(true)
["PluginDir"]=>
string(0) ""
["ConfirmReadingTo"]=>
string(0) ""
["Hostname"]=>
string(0) ""
["MessageID"]=>
string(0) ""
["MessageDate"]=>
string(31) "Fri, 27 Jan 2017 05:13:00 +0000"
["Host"]=>
string(14) "smtp.gmail.net"
["Port"]=>
int(465)
["Helo"]=>
string(0) ""
["SMTPSecure"]=>
string(3) "ssl"
["SMTPAutoTLS"]=>
bool(true)
["SMTPAuth"]=>
bool(true)
["SMTPOptions"]=>
array(0) {
}
["Username"]=>
string(26) "alisda.residency#gmail.com"
["Password"]=>
**********
["AuthType"]=>
string(0) ""
["Realm"]=>
string(0) ""
["Workstation"]=>
string(0) ""
["Timeout"]=>
int(300)
["SMTPDebug"]=>
bool(true)
["Debugoutput"]=>
string(4) "echo"
["SMTPKeepAlive"]=>
bool(false)
["SingleTo"]=>
bool(false)
["SingleToArray"]=>
array(0) {
}
["do_verp"]=>
bool(false)
["AllowEmpty"]=>
bool(false)
["LE"]=>
string(1) "
"
["DKIM_selector"]=>
string(0) ""
["DKIM_identity"]=>
string(0) ""
["DKIM_passphrase"]=>
string(0) ""
["DKIM_domain"]=>
string(0) ""
["DKIM_private"]=>
string(0) ""
["DKIM_private_string"]=>
string(0) ""
["action_function"]=>
string(0) ""
["XMailer"]=>
string(0) ""
["smtp":protected]=>
object(SMTP)#1552 (14) {
["Version"]=>
string(6) "5.2.22"
["SMTP_PORT"]=>
int(25)
["CRLF"]=>
string(2) "
"
["do_debug"]=>
bool(true)
["Debugoutput"]=>
string(4) "echo"
["do_verp"]=>
bool(false)
["Timeout"]=>
int(300)
["Timelimit"]=>
int(300)
["smtp_transaction_id_patterns":protected]=>
array(3) {
["exim"]=>
string(21) "/[0-9]{3} OK id=(.*)/"
["sendmail"]=>
string(29) "/[0-9]{3} 2.0.0 (.*) Message/"
["postfix"]=>
string(35) "/[0-9]{3} 2.0.0 Ok: queued as (.*)/"
}
["smtp_conn":protected]=>
bool(false)
["error":protected]=>
array(4) {
["error"]=>
string(0) ""
["detail"]=>
string(0) ""
["smtp_code"]=>
string(0) ""
["smtp_code_ex"]=>
string(0) ""
}
["helo_rply":protected]=>
NULL
["server_caps":protected]=>
NULL
["last_reply":protected]=>
string(0) ""
}
["to":protected]=>
array(1) {
[0]=>
array(2) {
[0]=>
string(23) "shivanand3939#gmail.com"
[1]=>
string(0) ""
}
}
["cc":protected]=>
array(0) {
}
["bcc":protected]=>
array(0) {
}
["ReplyTo":protected]=>
array(0) {
}
["all_recipients":protected]=>
array(1) {
["shivanand3939#gmail.com"]=>
bool(true)
}
["RecipientsQueue":protected]=>
array(0) {
}
["ReplyToQueue":protected]=>
array(0) {
}
["attachment":protected]=>
array(0) {
}
["CustomHeader":protected]=>
array(0) {
}
["lastMessageID":protected]=>
string(58) ""
["message_type":protected]=>
string(5) "plain"
["boundary":protected]=>
array(3) {
[1]=>
string(35) "b1_ab0450b0fa3fa25b2fadbefee8bd80f6"
[2]=>
string(35) "b2_ab0450b0fa3fa25b2fadbefee8bd80f6"
[3]=>
string(35) "b3_ab0450b0fa3fa25b2fadbefee8bd80f6"
}
["language":protected]=>
array(19) {
["authenticate"]=>
string(35) "SMTP Error: Could not authenticate."
["connect_host"]=>
string(43) "SMTP Error: Could not connect to SMTP host."
["data_not_accepted"]=>
string(30) "SMTP Error: data not accepted."
["empty_message"]=>
string(18) "Message body empty"
["encoding"]=>
string(18) "Unknown encoding: "
["execute"]=>
string(19) "Could not execute: "
["file_access"]=>
string(23) "Could not access file: "
["file_open"]=>
string(33) "File Error: Could not open file: "
["from_failed"]=>
string(35) "The following From address failed: "
["instantiate"]=>
string(36) "Could not instantiate mail function."
["invalid_address"]=>
string(17) "Invalid address: "
["mailer_not_supported"]=>
string(25) " mailer is not supported."
["provide_address"]=>
string(54) "You must provide at least one recipient email address."
["recipients_failed"]=>
string(45) "SMTP Error: The following recipients failed: "
["signing"]=>
string(15) "Signing Error: "
["smtp_connect_failed"]=>
string(22) "SMTP connect() failed."
["smtp_error"]=>
string(19) "SMTP server error: "
["variable_set"]=>
string(30) "Cannot set or reset variable: "
["extension_missing"]=>
string(19) "Extension missing: "
}
["error_count":protected]=>
int(2)
["sign_cert_file":protected]=>
string(0) ""
["sign_key_file":protected]=>
string(0) ""
["sign_extracerts_file":protected]=>
string(0) ""
["sign_key_pass":protected]=>
string(0) ""
["exceptions":protected]=>
bool(true)
["uniqueid":protected]=>
string(32) "ab0450b0fa3fa25b2fadbefee8bd80f6"
}
The SMTP debugging output is shown below:
2017-01-27 05:13:00 Connection: opening to ssl://smtp.gmail.net:465, timeout=300, options=array (
)
2017-01-27 05:13:00 Connection: Failed to connect to server. Error number 2. "Error notice: stream_socket_client(): php_network_getaddresses: getaddrinfo failed: Name or service not known
2017-01-27 05:13:00 Connection: Failed to connect to server. Error number 2. "Error notice: stream_socket_client(): unable to connect to ssl://smtp.gmail.net:465 (php_network_getaddresses: getaddrinfo failed: Name or service not known)
2017-01-27 05:13:00 SMTP ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: Name or service not known (0)
2017-01-27 05:13:00 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
I have also tried WP Gmail SMTP Plugin but again there is an error while sending emails.
Thank you for your help!
kindly check following setting in you SMTP setting page in admin:
- Mailer: Send all WordPress emails via SMTP.
- Encryption: Use SSL encryption.
- Authentication: Yes: Use SMTP authentication.
Then try test email.
Hope it will works for your code.
I have problem with parsing email message with PHP IMAP. Problem is that I have message signed with pkcs#7 signature. Mail contains some text and 2 attachments first one is smime.p7s and second one is message.htm which is html attachment I would like to parse.
To be honest I have no idea how can I access content of this file.
$hostname = '{host}INBOX';
$username = 'name';
$password = 'pass';
/* try to connect */
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());
/* grab emails */
$emails = imap_search($inbox,'UNSEEN');
$msg = Array();
if($emails) {
/* begin output var */
$output = '';
/* put the newest emails on top */
rsort($emails);
/* for every email... */
foreach($emails as $email_number) {
$overview = imap_fetch_overview($inbox,$email_number,0);
$message = imap_fetchbody($inbox,$email_number,2);
$structure = imap_fetchstructure ( $inbox,$email_number,FT_UID);
echo "<pre>";
var_dump($structure);
echo "</pre>";
break;
}
}
I get full structure and I can find there part:
object(stdClass)#16 (14) {
["type"]=>
int(0)
["encoding"]=>
int(4)
["ifsubtype"]=>
int(1)
["subtype"]=>
string(4) "HTML"
["ifdescription"]=>
int(0)
["ifid"]=>
int(0)
["lines"]=>
int(123)
["bytes"]=>
int(4473)
["ifdisposition"]=>
int(1)
["disposition"]=>
string(10) "attachment"
["ifdparameters"]=>
int(1)
["dparameters"]=>
array(1) {
[0]=>
object(stdClass)#17 (2) {
["attribute"]=>
string(8) "filename"
["value"]=>
string(37) "message.htm"
}
}
["ifparameters"]=>
int(1)
["parameters"]=>
array(2) {
[0]=>
object(stdClass)#18 (2) {
["attribute"]=>
string(4) "name"
["value"]=>
string(37) "message.htm"
}
[1]=>
object(stdClass)#19 (2) {
["attribute"]=>
string(7) "charset"
["value"]=>
string(8) "us-ascii"
}
}
}
Can anyone give me a hint how can I access content of message.htm ?
Since the structure does not have any parts defined, then the message is "simple".
Try using:
$message = imap_fetchbody($inbox,$email_number,0);
This will fetch the "0th" part of the message, which should be the body.
Check out the docs here: http://www.php.net/manual/en/function.imap-fetchstructure.php
EDIT: I don't think the final output looks like JSON. If not, what is it?
I have this code:
$url = 'http://eligibility.sc.egov.usda.gov/eligibility/eligibilityservice?eligibilityType=Property&requestString=<?xml version="1.0"?><Eligibility xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="/var/lib/tomcat5/webapps/eligibility/Eligibilitywsdl.xsd"><PropertyRequest StreetAddress1="'.$street.'" StreetAddress2="" StreetAddress3="" City="'.$city.'" State="'.$state.'" County="" Zip="'.$zip.'" Program="RBS"></PropertyRequest></Eligibility>';
$url_arr = explode( 'requestString=', $url );
$xml = simplexml_load_string( $url_arr[ 1 ] ); // requires allow_url_fopen to be on
$elg = (string)$xml->Property[Eligibility];
var_dump($xml);
$xml = simplexml_load_file($url); // requires allow_url_fopen to be on
$elg = json_encode((string)$xml->Property[Eligibility]);
var_dump($elg);
Which out puts this array:
object(SimpleXMLElement)#1 (1) {
["PropertyRequest"]=> object(SimpleXMLElement)#2 (1) {
["#attributes"]=> array(8) {
["StreetAddress1"]=> string(13) "7865 ILLINOIS"
["StreetAddress2"]=> string(0) ""
["StreetAddress3"]=> string(0) ""
["City"]=> string(10) "CASEYVILLE"
["State"]=> string(2) "IL"
["County"]=> string(0) ""
["Zip"]=> string(5) "62232"
["Program"]=> string(3) "RBS"
}
}
}
string(12) ""InEligible""
I just want to grab the string(12) ""InEligible"" portion. How would I put this into a variable?
From your code there $elg already holds this value, and it is a variable.
EDIT: I don't think the final output looks like JSON. If not, what is it?
string(12) ""InEligible""
That's JSON. A string in JSON is enclosed in quotes, no more, no less.