Mailer Error: Could not instantiate mail function in joomla - php

I have used following settings in joomla -adminpanel- global configuration-server
Mailer :Sendmail
Mail from :user
From Name :sales#user.com
Sendmail Path :/usr/sbin/sendmail
SMTP Authentication :No
SMTP Security :none
SMTP Port :25
SMTP Username:
SMTP Password :
SMTP Host :localhost
I have used form in site
<form action="email.php" method="post" name="emailForm" id="emailForm" class="form- validate">
in email.php i used php mailer as follows
<?php
require_once("class.phpmailer.php");
$mail = new PHPMailer();$mail->CharSet = 'UTF-8';
$email = $_REQUEST['email'] ;
$name = $_REQUEST['name'] ;
$message = $_REQUEST['text'] ;
// Enable encryption, 'ssl' also accepted
$mail->From = 'sales#example.com ';
$mail->FromName = 'Techzo';
$mail->addAddress('ccccc#example.in'); // Name is optional
$mail->WordWrap = 50; // Set word wrap to 50 characters
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Enquiry /Contact form';
$mail->Body = 'Name: $name\nEmail: $email\n\n$message';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
?>
I have searched and worked accordingly but not in use.As am new to these coding please help me to understand this issue

This happens when sendmail is not installed on your server (sendmail should be under /usr/sbin ). You will need to install sendmail or use an alternative, such as gmail (you can use gmail using the phpmailer class.

Thanks for all your suggestions.I have sorted out the problem a day before.
Problem is sendmail option is not available in that server, I have tried for SMTP with wrong port no(25) previously.587 is port no for the mail server.
BY USING SMTP with all their configuration settings i done through it.

Related

Connecting to php mail sever without php-library

How to connect a php testing server like https://mailtrap.io/ .
If i have defined variables like
$host = 'mail.sample.com';
$port=25;
$user="username";
$pass="secret";
maybe also $Auth = "PLAIN, LOGIN and CRAM-MD5" $TLS="Optional (STARTTLS on all ports)";
How to use these variables, nowhere i can find samples.
I want to use simple php mail function.
mail($to, $subject, $message, $headers);
Thank you
Mailtrap is a fake SMTP server. However, the built-in PHP mail() function is simple and lacks SMTP authentication support ā€” which is required by mailtrap.
So, move on an and use a PHP mailer package like PHPMailer, Swift Mailer, PearMail, etc as shown here https://blog.mailtrap.io/php-email-sending/
E.g. with PHPMailer
use PHPMailer\PHPMailer\PHPMailer;
require_once './vendor/autoload.php';
$mail = new PHPMailer();
// configure an SMTP
$mail->isSMTP();
$mail->Host = 'smtp.mailtrap.io';
$mail->SMTPAuth = true;
$mail->Username = '1a2b3c4d5e6f7g';
$mail->Password = '1a2b3c4d5e6f7gā€™;
$mail->SMTPSecure = 'tls';
$mail->Port = 2525;
$mail->setFrom('confirmation#hotel.com', 'Your Hotel');
$mail->addAddress('me#gmail.com', 'Me');
$mail->Subject = 'Thanks for choosing Our Hotel!';
$mail->isHTML(TRUE);
$mail->Body = '<html>Hi there, we are happy to <br>confirm your booking.</br> Please check the document in the attachment.</html>';
$mail->AltBody = 'Hi there, we are happy to confirm your booking. Please check the document in the attachment.';
if(!$mail->send()){
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
There are other, haphazard options but I bet they are not working in your case. One of them is changing mail directives in php.ini and sendmail.ini (if you have access to it and feel adventurous).

How can I send a confirmation mail to an email ID from local host without a domain name?

Once my code is run in PHP, it says that the confirmation mail has been sent successfully, but the mail has not been received at the target mail ID. I have used the mail() function in PHP to send the confirmation mail and I have also installed Postfix on my Ubuntu. What is the problem here?
<?php
include('config.php');
$tb_name = temp_members_db;
$confirm_code = md5(uniqid(rand()));
$name = $_POST['name'];
$email = $_POST['email'];
$pass = $_POST['pass'];
$country = $_POST['country'];
$sql = "INSERT INTO $tb_name(confirm_code,name,email,password,country) VALUES ('$confirm_code','$name','$email','$pass','$country')";
$result = mysql_query($sql);
if($result) {
$to = $email;
$sub = "Your Confirmation Code";
$message = "Your confirmation code is" . $confirm_code;
$send = mail($to,$sub,$message);
var_export($send);
} else {
echo "Havent found email ID in our database";
}
if($send) {
echo "Sent the confirmation link to your email ID";
} else {
echo "Sending failed";
}
?>
Have you switched on the SMTP function on the localhost server?
If not enabled the SMTP and mail functions
Use PHPMailer class. Very easy to install and use. The PHP mail() function usually sends via a local mail server, typically fronted by a sendmail binary on Linux, BSD and OS X platforms, however, Windows usually doesn't include a local mail server; PHPMailer's integrated SMTP implementation allows email sending on Windows platforms without a local mail server.
Just download the class files from here: https://github.com/PHPMailer/PHPMailer
Example:
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
Set SMTP and if you want to use secure encryption (ssl,tls and ports)
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'user#example.com'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // If you want to use encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to(or port 25,465 etc)
Set fields like from, to, bcc, subject, email body etc.
$mail->setFrom('from#example.com', 'Mailer');
$mail->addAddress('joe#example.net', 'Joe User'); // Add a recipient
// Name is optional
$mail->addReplyTo('info#example.com', 'Information');
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}

Mailer error: Could not instantiate mail function for php mailer function

I want to sent mail by using xampp.So I used phpmailer function.But I got these error "Mailer error: Could not instantiate mail function".
My php code is following
$mail = new PHPMailer();
$mail->Host = "localhost"; // SMTP server
$mail->Port = 25;
$mail->SMTPAuth = true;
$mail->Username = "myothantspo#gmail.com";
$mail->Password = "password";
$mail->From = "myothantspo#gmail.com";
$mail->AddAddress("webdev3#myanmars.net");
$mail->Subject = "no subject";
$mail->Body = "this is a test message";
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}
My setting for php.ini is following
[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25
; For Win32 only.
sendmail_from = myothantspo#gmail.com
Most of your configuration (Host, Port, SMTPAuth etc) relates to PHPMailer's own SMTP handler rather than PHP's built-in mail function.
If, as it therefore appears, you want PHPMailer to send email using SMTP instead of mail then you need to add $mail->IsSMTP(); to your code somewhere before you call $mail->Send().
Did you include phpmailer? Like this:
require 'PHPMailerAutoload.php';
Or you might want to check this:
https://github.com/PHPMailer/PHPMailer

Sending mails using Mandrill PHPmailer is not working

I want to use Mandrill for sending my emails. I am customizing my phpmailer which I had used to send the mail with mandrill phpmailer. (found here: http://help.mandrill.com/entries/23737696-How-do-I-send-with-PHPMailer- )
require 'mandrillmailer/class.phpmailer.php';
$mail = new PHPMailer();
$mail->IsSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.mandrillapp.com'; // Specify main and backup server
$mail->Port = 587; // Set the SMTP port
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'MANDRILL_USERNAME'; // SMTP username
$mail->Password = 'MANDRILL_APIKEY'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
$mail->From = 'from#example.com';
$mail->FromName = 'Your From name';
$mail->AddAddress($to); // Add a recipient
$mail->IsHTML(true); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body = $message;
echo $mail->Subject;
//$mail->Send();
//$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->Send()) {
echo 'hiii';
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
else{
echo 'hello';
echo 'Message has been sent';
}
die('here');
I am not getting response messages i.e mail is sent or not. I debugged where it is getting stuck by echo statements. I can see the messages till echo $mail->Subject; but not beyond that. I am guessing that $mail->Send() is not working that's why messages beyond that are not displaying and email sending is not working.
How do I fix that?
Assuming you've put in the proper authorization, try it by requiring the autoloader rather than phpmailer class. This worked for me:
require 'mandrillmailer/PHPMailerAutoload.php';
Alternatively you could try something a little easier. Something like the official Mandrill PHP client or a separate service like sendwithus.
First of all check the PHPMailer class version If Its below Version 5 then use the latest version 5.2.9
My issue resolved as I used the Version 5.2.9

Can not send mail from external SMTP on heroku?

I used the following code in my app to send a mail from my heroku app
<?php
require("PHPMailer-master/class.phpmailer.php");
require("PHPMailer-master/class.smtp.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "smtp.gmail.com"; // SMTP server
$mail->From = "suneetha.itham#gmail.com";
$mail->AddAddress("suneetha#yantranet.com");
$mail->Subject = "First PHPMailer Message";
$mail->Body = "Hi! \n\n This is my first e-mail sent through PHPMailer.";
$mail->WordWrap = 50;
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
}else {
echo 'Message has been sent.';
}
?>
But, my app is showing up
"Message was not sent.Mailer error: The following From address failed: suneetha.itham#gmail.com : MAIL FROM command failed,530,5.7.0 Must issue a STARTTLS command first. h20sm18987465qen.5 - gsmtp" \n
Can any one help me to solve this problem.Thanks.
I think this more a issue with your smtp config's See this answer: https://stackoverflow.com/a/16048485/959041
Does your code work on your local machine?

Categories