We are using amazon server and I am using PHP, Codeigniter framework.
Below is the script which I am using for sending emails.
It is working when I send an email to Gmail domain email id (abc#gmail.com) but it is not working on some specific domain name email id (abc#xyzdmainname.com).
public function sendMail() {
$to = 'abc#xyzdomain.com';
$fromEmail = 'pqr#gmail.com';
$fromName = 'pqr';
$subject = 'Testing';
$message = 'Testing of email';
$newFile = ''
$this->CI->load->library('email');
$this->CI->email->mailtype = 'html';
$this->CI->email->from($fromEmail, $fromName);
$this->CI->email->to($to);
$this->CI->email->subject($subject);
$this->CI->email->message($message);
if (!empty($newFile)) {
$this->CI->email->attach($newFile);
}
$result = $this->CI->email->send();
$message = '';
if ($result) {
return 1;
} else {
echo $this->CI->email->print_debugger();
return 0;
};
Please let me help what-what case may be here for fail sending email on a particular domain.
and How I can overcome this issue.
Related
i made a php function to send mail using phpmailer. but, there is a problem in the function. it neither send mail nor shows error. please help me out. i'm fetching mail body and some other details from other functions and its working fine except it doesn't send mail and i think there must be some problem with the host,port,username,etc.
please help me out.
thanks
my funciton:
public static function sendEmail($data) {
$r_error = 1;
$r_message = "";
$r_data = array();
$q = "select * from config where type='email_detail'";
$r = self::DBrunQuery($q);
$row = self::DBfetchRow($r);
$detail = json_decode($row['value'], true);
include "phpmailer/PHPMailerAutoload.php";
if (!empty($data['email'])) {
foreach ($data as $var) {
$work_email = 'fahadansari12feb#gmail.com'; //$var['email_id'];
$name = 'fahad'; //$var['name'];
$subject = $var['subject'];
$body = $var['body'];
$cc = $var['cc_detail'];
$bcc = $var['bcc_detail'];
$file_upload = $var['upload_file'];
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 0;
$mail->Debugoutput = 'html';
$mail->Host = '5.9.144.226'; //$detail['host'];
$mail->Port = '2222'; //$detail['port'];
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = 'fahadansari12feb#gmail.com'; //$detail['username']; //sender email address
$mail->Password = 'mypassword'; //$detail['password']; // sender email password
$mail->setFrom('hr#excellencetechnologies.in', 'Excellence Technologies'); // name and email address from which email is send
$mail->addReplyTo('hr#excellencetechnologies.in', 'Excellence Technologies'); // reply email address with name
$mail->addAddress($work_email, $name); // name and address to whome mail is to send
if (sizeof($cc) > 0) {
foreach ($cc as $d) {
$mail->addCC($d[0], $d[1]);
}
}
if (sizeof($bcc) > 0) {
foreach ($bcc as $d2) {
$mail->addBCC($d2[0], $d2[1]);
}
}
$mail->Subject = $subject; // subject of email message
$mail->msgHTML($body); // main message
// $mail->AltBody = 'This is a plain-text message body';
//Attach an image file
if (sizeof($file_upload) > 0) {
foreach ($file_upload as $d3) {
$mail->addAttachment($d3);
}
}
//send the message, check for errors
if (!$mail->send()) {
$row3 = $mail->ErrorInfo;
} else {
$row3 = "Message sent";
}
}
}
if ($row3 != "Message sent") {
$r_error = 1;
$r_message = $row3;
$r_data['message'] = $r_message;
} else {
$r_error = 0;
$r_message = "Message Sent";
$r_data['message'] = $r_message;
}
$return = array();
$return['error'] = $r_error;
$return['data'] = $r_data;
return $return;
}
You've not posted enough info, but I'm going to guess your problem. You're enabling TLS, but you're connecting to an IP address rather than a host name, so your host name will never match the name on the certificate and you will get a TLS validation failure on SMTP connections.
Connect to a named host with a valid certificate, or disable certificate checks (see PHPMailer docs for how to do that), though that's not recommended.
You're also using an old version of PHPMailer, so upgrade.
I am working on a project that needs to send email.I use this as my controller
$from_email = $this->input->post('email');
$to_email = "info#test.com";
$name = $this->input->post('name');
$phno = $this->input->post('phno');
$from = $this->input->post('start');
$to = $this->input->post('end');
$message = $this->input->post('message');
$bodyContent="<table>
<tr><td>Name:</td><td>$name</td></tr>
<tr><td>Phno:</td><td>$phno</td></tr>
<tr><td>From Date:</td><td>$from</td><td>To Date:</td><td>$to</td></tr>
<tr><td>Message:</td><td>$message</td></tr>
</table>";
//Load email library
$this->load->library('email');
$this->email->from($from_email, $name);
$this->email->to($to_email);
$this->email->subject('Enquiry From Test TOURS');
$this->email->message($bodyContent);
//Send mail
if($this->email->send()) {
$this->session->set_flashdata("email_sent","Email sent successfully.");
} else {
$this->session->set_flashdata("email_sent","Error in sending Email.");
}
redirect('test_view/index');
And I am getting the output in the mail as like this
<table>
<tr><td>Name:</td><td>wer</td></tr>
<tr><td>Phno:</td><td>wer</td></tr>
<tr><td>From Date:</td><td>10/18/2017</td><td>To
Date:</td><td>10/25/2017</td></tr>
<tr><td>Message:</td><td>wer</td></tr>
</table>
I don't know why i am getting output in the mail like this , can anyone sortout this error please.
use mailtype configuration 'html' in Email configuration file
$config['mailtype'] = 'html';
from user guide
You need to set the type as html :
$this->email->set_mailtype("html");
Thanks in advance to all. I am designing a shopping cart in php and mysql. I want to send order confirmation email to the client and also to admin registered email-id. My email function is
function send_mail($address,$subject,$message,$path){
global $error;
$mail = new PHPMailer();
//$mail->isSMTP();
//$mail->SMTPDebug = 1; // Enable verbose debug output
//$mail->SMTPAuth = true;
//$mail->SMTPSecure ='ssl' ;
//$mail->Host ="smtp.mail.yahoo.com";
//$mail->Port = '465'; // use 587 also
//$mail->Username = "";
//$mail->Password = "";
$mail->setFrom("sales#dressncrafts.com", "Dress N Crafts");
$mail->addReplyTo("sales#dressncrafts.com", "Dress N Crafts");
$mail->addAddress($address); // Add a recipient
$mail->Subject = $subject;
//$mail->AltBody = $message; // optional, comment out and test
$mail->MsgHTML($message);
$mail->addAttachment($path); // attachment
$send = $mail->send();
$mail->clearAddresses();
$mail->clearAttachments();
if(!$send) {
return FALSE;
} else {
return TRUE;
}
}
Now the problem is when I triggered the function to send mail, only customer email is sent but admin email is not sending. I have tried to input sleep function, use the same function in a different name, but all gone in vain. The absurd thing is that if I changed the order of the mail, only customer mail is sending. Please help me to solve the problem. thank you. the very code is
$message = "Hello $name, your order (order number:$ordernumber) has been
placed on the date $date with the following details."
.'<br><br><center>'.$body.'</center><br>'."Subtotal:Rs.
$subtotal".'<br>'."Delivery Charges:Extra".'<br>'."Total:Rs.
$total".'<br>'.
"Your order is under process and the invoice is attached with the
mail.Please find it.".'<br><br>'.
"Thanking you".'<br>'.$about->getShopname();
$subject = "Successful order";
$cust_mail=send_mail($email,$subject,$message,$invpath);
$shopsubject = "New Order";
$shop_email= $about->getEmail();
$shop_mail= send_mail($shop_email,$shopsubject,"New order has arrived, find
the attachment",$invpath);
if($shop_mail==TRUE && $cust_mail==TRUE){
foreach($cartresult as $cres)
{
$cart->setIdcart($cres->idcart);
$cart->deleteCart();
}
redirect("../checkout.php?plsord=TRUE&cust={$cust_mail}&shop=
{$shop_mail}");
}
else {
foreach($cartresult as $cres)
{
$cart->setIdcart($cres->idcart);
$cart->deleteCart();
}
redirect("../checkout.php?plsord=TRUE&some=false&cust=
{$cust_mail}&shop={$shop_mail}");
}
I'm using Swift Mailer v3.3.2 to send emails from my app and I need to be able to change the text of the sender.
My code looks like this:
//Sending email
$swift = email::connect();
$email_message = new View('email/email_template');
$subject = "Subject here";
$from = "subdomain#domain.org";
$email_message->content_email = new View('email/content/signup');
$email_message->content_email->user = $user;
$message = $email_message;
$recipients = new Swift_RecipientList;
$recipients->addTo($user->email);
// Build the HTML message
$message = new Swift_Message($subject, $message, "text/html");
if ($swift->send($message, $recipients, $from)) {
;
} else {
;
}
$swift->disconnect();
I want to be able to set the name text of the sender as 'Senders_Name Senders_Surname', even though the sender is still subdomain#domain.org
Any clue on how to do that?
After line
$message = new Swift_Message($subject, $message, "text/html");
you should add
$message->setFrom(new Swift_Address($from , 'Senders_Name Senders_Surname'));
The whole working script below (I've just tested it in 3.3.2 version):
<?php
require ('lib/Swift.php');
require('lib/Swift/Connection/SMTP.php') ;
$smtp = new Swift_Connection_SMTP();
$smtp->setServer('server');
$smtp->setUsername('username');
$smtp->setPassword('password');
$smtp->setEncryption($smtp::ENC_SSL);
$smtp->setPort(465);
$swift = new Swift($smtp);
$swift->connect();
$subject = "Subject here";
$from = 'test#email.com';
$message = 'test message';
$recipients = new Swift_RecipientList;
$recipients->addTo('mymail');
// Build the HTML message
$message = new Swift_Message($subject, $message, "text/html");
$message->setFrom(new Swift_Address($from , 'Senders_Name Senders_Surname'));
if ($swift->send($message, $recipients, $from)) {
;
} else {
;
}
$swift->disconnect();
Below image how the sender is displayed in email client (Thunderbird for me) so it works fine. If you test it in your email client make sure you don't have account from set as one of your mail accounts. In that case email client shows for example "Me" or sth else. The best for test just fill in addTo with your email and smtp settings and leave from and other parts unchanged
So I'm trying to use PHPMailer to handle the email form on my website.
I wrote the code here based on a tutorial I found.
<?php
error_reporting(E_ALL);
require_once("class.phpmailer.php");
include("class.smtp.php");
$email = new PHPMailer();
//
// Set server details for send
//
$email->IsSMTP();
$email->Host = "mail.loganyoung.za.net";
$email->Port = 25;
$email-SMTPAuth = true;
$email->Username = "<my email>";
$email->Password = "<my password>";
//
// Send mail from the contact form
//
$to = "<my email>";
$from = $_POST["from"];
$name = $_POST["name"];
$subject = "From web: ".$_POST["subject"];
$message = $_POST["message"];
$body = "<p>Hi Logan,</p>";
$body .= "<p>You have received a new query on your website.<br />Please see below:</p>";
$body .= "<p>";
$body .= str_replace("\r\n", "<br />", $message);
$body .= "</p>";
$email->SetFrom($from, $name);
$email->AddReplyTo($from, $name);
$email->AddAddress($to, "LoganYoung.za.net");
$email->Subject = $subject;
$email->Body = $body;
$email->IsHTML = true;
session_start();
if(!$email->Send()) {
$_SESSION["mailresult"] = "success";
echo "success";
} else {
echo "<p>Failed:</p><p>".$email->ErrorInfo."</p>";
$_SESSION["mailresult"] = "failed";
$_SESSION["mailerror"] = $email->ErrorInfo;
}
?>
I figure possible reasons for it not sending could be...
Incorrect SMTP details (possibly send without SMTP auth to resolve?)
Handler isn't getting POST data (the ajax that sends it seems to work fine though)
Some problem with this code that I'm not able to identify...
As a means of eliminating possibilities, can anyone spot anything wrong with the code here? If so, what's wrong, and how do I fix it?
Thanks in advance!
$email-SMTPAuth = true;
Isn't that supposed to be:
$email->SMTPAuth = true;