XAMMP Sendmail issue - php

I am having an issue getting my sendmail to work in Xammp.
The mail was working perfectly when using sendtodisk but now I get a crash log using sendmail:
PHP to send emails (Using PHP Mailer):
$mail = new PHPMailer;
$mail->setFrom($from_email, 'Thomas ****');
$mail->addAddress('thomas#****.co.za', 'Client');
$mail->Subject = 'Sign Offs';
$mail->Body = generateMailTemplate($job_id, $to_email, $from_email, $name);
$mail->addAttachment('tmp/'.$job_id.'.pdf');
$mail->isHTML(true);
if (!$mail->send()) {
return $mail->ErrorInfo;
} else {
return true;
}
php.ini
sendmail_path = "C:\xampp\sendmail\sendmail.exe -t"
sendmail.ini
smtp_server=outbound.mailhop.org
smtp_port=25
crash.log
command line : C:\xampp\sendmail\sendmail.exe -t -fthomas#****.co.za
Any ideas?

try to set smtp settings for your phpmailer script, not for php
$mail = new PHPMailer();
$mail->isSMTP();
$mail->Host = 'outbound.mailhop.org';
$mail->Port = 25;
// if need auth
$mail->SMTPAuth = true;
$mail->Username = 'user';
$mail->Password = 'password';
$mail->Subject = 'subject';
$mail->Body = 'body';
$mail->send();

Related

Mail() problem, the mail that i send from php doesnt arrive

I'm trying to send emails with php in local, i have modified php.ini and sendmail.ini but still still doesnt work.
The IDE doesn't even give me Errors or a Warnings like Failed to connect to mailserver at "localhost" port 25 or something like that
php.ini
SMTP=smtp.gmail.com
smtp_port=465
sendmail_from = biagiosani2005#gmail.com
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
and sendmail.ini
smtp_server=smtp.gmail.com
smtp_port=465
error_logfile=error.log
debug_logfile=debug.log
auth_username=biagiosani2005#gmail.com
auth_password=xxxxxxxx
force_sender=biagiosani2005#gmail.com
<?php
$to = "luciasani2005#gmail.com";
$subject = "this is a subject";
$message = "this is a message";
mail($to, $subject, $message);
?>
It is not SMTP send mail. You have SMTP configurations, it is okay, but your sending way is wrong. You need to use PHPMailer package and to correct script such:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require './PHPMailer-master/src/Exception.php';
require './PHPMailer-master/src/PHPMailer.php';
require './PHPMailer-master/src/SMTP.php';
$html = "<h1>Hello </h1>";
$mail = new PHPMailer(true);
try {
//Server settings
$mail->isSMTP();
$mail->Host = 'smtp.titan.email';
$mail->SMTPAuth = true;
$mail->Username = 'contact#domain.com';
$mail->Password = 'password';
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
//Recipients
$mail->setFrom('contact#domain.com', 'domain Team');
$mail->addAddress('receiver1#gmail.com', 'Joe User');
$mail->addAddress('receiver2#gmail.com', 'Joe User');
// Attachments
// Content
$mail->isHTML(true);
$mail->Subject = 'Here is the subject';
$mail->Body = $html;
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
echo true;
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}

phpmailer on windows IIS

I am trying to configure PHPMailer in order to have it working ona Windows IIS server using php scripts.
The application I have is written in PHP so we expected we could easily use PHPMailer to send emails.
Well, that doesn't work.
We have tried configuring it as SMTP, but we still get error in configuration.
Here it is our script:
date_default_timezone_set('Etc/UTC');
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 1;
//$mail->Debugoutput = 'html';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = "account#gmail.com";
$mail->Password = "gmailPWD";
$mail->setFrom('info#website.com', 'The Website');
$mail->addAddress($to, '');
$mail->Subject = $subject;
$mail->msgHTML($message);
if (!$mail->send()) {
$errors = "Errori Mailer: " . $mail->ErrorInfo;
} else {
$errors = "<h5>Sent!</h5>";
}
Any clue? How can that be used on windows server?
Thank you
EDIT
So, it was a problem of Gmail and its security settings. I followed this post: https://stackoverflow.com/a/25175234/1873501 and everything went smooth!
I just wanted to share it.
You've downloaded and extracted the class I am assuming. Maybe you're not autoloading? Make sure you include:
require '/path/to/PHPMailerAutoload.php';
It should be fine on IIS/Windows Server. See some of the examples here in the documentation (and in the examples folder): https://github.com/PHPMailer/PHPMailer
Also, if you are getting any errors make sure you list them so we know how to help you further.
function sendMail($request) {
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->SMTPDebug = 4;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'yourmail#gmail.com;
$mail->Password = 'yourgamilPass';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom('yourgmail#gmail.com', 'Title');
$mail->addAddress(emailsendingto#gmail.com);
$mail->addReplyTo('yourgmail#gmail.com');
$mail->isHTML(true);
$mail->Subject = '$the subject of the e-mail';
$mail->Body = 'The body of the email';
$mail->AltBody = 'Alternative'; // this is mostly sent to your own mail
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
}

PHP mailer smtp setup with gmail

Hello guys I have stuck with this problem for a while now. I am trying to send mail from xampp. I have went through several solutions posted here but none of them seem to work still. kind of need someone to point me to the right direction.
so in my php.ini
[mail function]
SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = user#gmail.com
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
I also have the sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t" commented with a ;
now in my sendmail.ini
[sendmail]
smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username=user#gmail.com
auth_password=123456
force_sender=shadidhaque2014#gmail.com
P.s: I only have the above code in sendmail.ini
now for the php script I have something very simple:
$send=mail('rzs2009#yahoo.com', 'subject', 'blah blah blah');
if ($send) {
# code..
echo "yes";
}else
{
echo "no";
}
now everytime I try to run the program I get a no. So no email is being sent. Where might I be going wrong.
Thanks in advance.
Modify your code like this:
function smtpmailer($to, $from, $from_name, $subject, $body) {
global $error;
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 0; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->Username = GUSER;
$mail->Password = GPWD;
$mail->SetFrom($from, $from_name);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress($to);
if(!$mail->Send()) {
$error = 'Mail error: '.$mail->ErrorInfo;
return false;
} else {
$error = 'Message sent!';
return true;
}
}
http://www.web-development-blog.com/archives/send-e-mail-messages-via-smtp-with-phpmailer-and-gmail/

use phpmailer to send email from localhost to gmail: SMTP connect() failed

i want to send an email from localhost to gmail, but it says "SMTP connect() failed"
here is my code. I've also tried to change configuration php.ini and sendmail.ini but no luck.
Thank you.
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPSecure = 'ssl';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->Username = 'asd#gmail.com';
$mail->Password = 'password';
$mail->From = 'from#example.com';
$mail->FromName = 'Mailer';
$mail->addAddress('asd#gmail.com');
$mail->WordWrap = 50;
$mail->isHTML(true);
$mail->Subject = 'Email'
$mail->Body = "This is body";
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
Try out the following :
Ensure that the PHPMailer library is included in the code.
Ensure that you are internet connection from localhost is not inhibited by any proxy.
Happy Coding :)
check the line $mail->Subject = 'Email' for a missing ;

Running PHP script from cmd than getting SMTP connection failed()

I m tryinng to send mail using following script. This scrips works fine if I execute this script in browser But if I run this script through command-line(cmd ) than getting smrp connection failed() error.
code :
function sendMail($subject,$cc,$bcc,$emailcontent){
global $_mailmsg;
$emailcontent=$_mailmsg;
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup server
$mail->Port = '465';
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'username#gmail.com'; // SMTP username
$mail->Password = 'XXXXXXXX';
$mail->SMTPSecure = 'ssl';
$mail->From = 'username#gmail.com';
$mail->FromName = 'Notification';
$mail->addAddress('abc#gmail.com'); // Add a recipient
$mail->addReplyTo('username#gmail.com');
if(!empty($cc)){ $mail->addCC($cc); }
if(!empty($bcc)){ $mail->addBCC($bcc);}
$mail->WordWrap = 50; // Set word wrap to 50 characters
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body = $emailcontent;
try
{
if($mail->send()) {
return 1;
exit;
}
else
{
echo 'Mailer Error: ' . $mail->ErrorInfo;
return 0;
}
}
catch(Exception $e)
{
return 0;
}
}
I also config php.ini file
; For Win32 only.
; http://php.net/smtp
SMTP = smtp.gmail.com
; http://php.net/smtp-port
smtp_port = 465
; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = username#gmail.com
To run php file i wrote the following things in cmd
php filename.php

Categories