I m using Wamp Server (Local Host)
Error Message
A PHP Error was encountered
Severity: Warning
Message: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()
Filename: libraries/Email.php
Line Number: 1553
Controller
if ($this->form_validation->run() == TRUE)
{
//Email Verification
$key = md5(uniqid());
$this->load->library('email',array('mailtype'=>'html'));
$this->email->from ('info#worldquotes.in','Admin');
$this->email->to($this->input->post('email'));
$this->email->Subject('Confirm YOur Account');
$message = "<p> thank you for Signing Up </p>";
$message .= "<p> <a href= '".base_url()."main/register_user/$key '> Click here </a> to Confirm Your Account </p>";
$this->email->message($message);
if ($this->email->send()) {
echo "Then Email has been Send";
}else echo "Could ot send the Email, Contact info#worldquotes.in";
}
else
{
$this->load->view('signup');
}
}
May I know why that error message came and how to resolve?
You need to configure your server for mailing first. Take a look at this handy tutorial and you should be on your way.
http://roshanbh.com.np/2007/12/sending-e-mail-from-localhost-in-php-in-windows-environment.html
If you're having trouble figuring out your ISP's SMTP server, you could take a look in this catalog:
http://www.arclab.com/products/amlc/list-of-smtp-and-pop3-servers-mailserver-list.html
Hope this helps!
Related
In facts I found this question: Laragon and Laravel - sendmail not working ... but I decided to post a detailed new question, to get a response, that this issue is possibly a laravel bug... Thank you.
OS: Windows 10
Laravel Version: 8.75
PHP Version: 7.4.27
Database Driver & Version: sqlite
Description:
I trying around getting sendmail (Laragon) to work, but without luck.
File '.env' got adjusted to use sendmail instead of smtp on a fresh laravel project.
Steps To Reproduce:
created new laravel project
laravel new test
adjusted .env file:
MAIL_MAILER=sendmail
MAIL_SENDMAIL_PATH='C:\LARAGON\bin\sendmail\sendmail.exe -bs'
run command:
php artisan tinker
run tinker command:
Mail::raw('Hello World!', function($msg) {$msg->to('mail#example.com')->subject('Test Email'); });
After running the tinker command, the cmd is hanging...
Also tried different options on the sendmail flags:
sendmail.exe -t -i <<< tinker hangs
sendmail.exe -t <<< tinker hangs
sendmail.exe -bs <<< tinker hangs
I can see that the sendmail.exe is running (in task manager), but seems not be able to finish (waited several minutes).
Cancelation (CTRL-c) will close the tinker session and the sendmail.exe ist terminated.
With other php built-in mail function Laragon is working fine and also successfully catching the sent mails in the mail folder.
I always tried to clear configuration cache after every change of the .env file.
php artisan config:clear
Sending mail via php works fine as expected with the following code:
<html>
<head>
<title>Sending HTML email using PHP</title>
</head>
<body>
<?php
$to = "xyz#somedomain.com";
$subject = "This is subject";
$message = "<b>This is HTML message.</b>";
$message .= "<h1>This is headline.</h1>";
$header = "From:abc#somedomain.com \r\n";
$header .= "Cc:afgh#somedomain.com \r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html\r\n";
$retval = mail ($to,$subject,$message,$header);
if( $retval == true ) {
echo "Message sent successfully...";
}else {
echo "Message could not be sent...";
}
?>
</body>
</html>
Any help really appreciated.
Generally this happens when there is an authentication issue with sendmail.
Make sure you have setup sendmail with your gmail credentials, as suggested by the Laragon Documentation
Additionally, gmail disables "less secure apps" by default. Make sure your account has less secure apps enabled here too (or even better, use an Application Specific Password): https://myaccount.google.com/lesssecureapps
output phpinfo() and check if you have the exact location define on sendmail_path
you also need to define it inside config/mail.php like
'sendmail' => [
'transport' => 'sendmail',
'path' => '/usr/sbin/sendmail -bs',
],
or pull the value from your .env file MAIL_SENDMAIL_PATH
'path' => env('MAIL_SENDMAIL_PATH')
Additionally, you may try using smtp driver with localhost info in your .env file, you can see these details in phpinfo() as well
MAIL_DRIVER=smtp
MAIL_HOST=localhost
MAIL_PORT=25
MAIL_USERNAME=
MAIL_PASSWORD=
MAIL_ENCRYPTION=null
try creating a route to send the email or dump the error
Route::get('/test-mail', function () {
try {
$send = \Illuminate\Support\Facades\Mail::mailer('sendmail')->send([], [], function ($message) {
$message
->to('to#email.com')
->from('from#email.com', 'Test')
->subject( 'My Subject' )
->setBody('Test Content', 'text/html');
});
dd($send);
} catch (\Exception $e ) {
throw new \Exception( $e->getMessage() );
}
});
Hello i am working windows 7 and online server. I want that the visitor send me a mesaj from contact form but when i click the submit button a problem occurs.
this is my controller;
public function ilet(){
$name = $this->input->post("name");
$email = $this->input->post("email");
$message = $this->input->post("message");
$config = array(
"protocol" => "smtp",
"smtp_host" => "smtp.gmail.com",
"smtp_port" =>"587",
"smtp_user" =>"dcugurel7#gmail.com",
"smtp_password" =>"*******",
"starttls" =>true,
"charset" =>"utf-8",
"mailtype" =>"html",
"wordwrap" => true,
"newline" =>"\r\n",
);
$this->load->library("email", $config);
$this->email->from("cugurel7#gmail.com");
$this->email->to("cugurel7#gmail.com");
$this->email->subject("Müşteri bilgi mesajı");
$this->email->message("Kişinin Adı - " . $name .
" - Kişinin Email Adresi - " . $email . " - Kişinin Mesajı - " . $message);
$send = $this->email->send();
if($send)
{
echo "Mail gönderme işlemi başarılı";
}
else {
echo "Başarısız<br>;";
echo $this->email->print_debugger();
}
}
bu when i click to submit button server says that ;
220 smtp.gmail.com ESMTP y189-v6sm1286718wmd.19 - gsmtp
hello: 250-smtp.gmail.com at your service, [185.85.237.26]
250-SIZE 35882577
250-8BITMIME
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250 SMTPUTF8
Failed to send AUTH LOGIN command. Error: 530 5.7.0 Must issue a STARTTLS command first. y189-v6sm1286718wmd.19 - gsmtp
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.
Can you please help me how can i fix this?
You connection code might be incorrect, take a look at this post and try this - Send email using the GMail SMTP server from a PHP page
In my Laravel project, I am using the laravelgooglemaps api by farhanwazir on my "contact us" page to display a fixed location.
Route for contactus page:
Route::get('/contactus', function () {
$config['center'] = 'California State University, Fullerton';
$config['zoom']='15';
$config['map_height'] = "300px";
$config['map_width'] = "300px";
$config['scrollwheel']= false;
GMaps::initialize($config);
$marker['position'] = 'California State University, Fullerton';
$marker['infowindow_content'] = 'Easywash Centre';
GMaps::add_marker($marker);
$map = GMaps::create_map();
return view('contactus')->with('map', $map); });
In my contactus.blade.php file:
{!! $map['html'] !!}
But sometimes when I load the "contact us" page I get the error:
ErrorException (E_WARNING)
file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed
Can anyone help me understand why I am getting such error and how it can be solved?
Try this:
$arrContextOptions=array(
"ssl"=>array(
"verify_peer"=>false,
"verify_peer_name"=>false,
),
);
file_get_contents($link, false, stream_context_create($arrContextOptions));
Just in case anyone wondering I solved this error by changing https:// to http:// .
my problem is that PHPMailer (PHPMailer-master 6.0.3 to be exact) does not deliver emails when I run it with Xampp and Windows10.
(I found a lot of comments on that subject but none of them led to a solution.)
The following code runs fine on a remote server:
<?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
// 'PHPMailer' here actually is the original folder 'PHPMailer-master'
// from unpacking the downloaded file PHPMailer-master.zip
require 'vendor/PHPMailer/src/Exception.php';
require 'vendor/PHPMailer/src/PHPMailer.php';
require 'vendor/PHPMailer/src/SMTP.php';
echo (extension_loaded('openssl')?'SSL loaded':'SSL not loaded')."\n";
$mail = new PHPMailer(true); // Passing `true` enables exceptions
try {
//Server settings
$mail->SMTPDebug = 2; // Enable verbose debug output
$mail->$mail->isSendmail(); // corrected
$mail->Host = 'smtp.kabelmail.de'; //smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'myname#kabelmail.de'; // SMTP username
$mail->Password = 'mypassword'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // TCP port to connect to
//Recipients
$mail->setFrom('from#example.com', 'Mailer');
$mail->addAddress('myname#kabelmail.de', 'myname'); // Add a recipient
// $mail->addAddress('ellen#example.com'); // Name is optional
$mail->addReplyTo('myname#web.de', 'Antwort');
//$mail->addCC('cc#example.com');
//$mail->addBCC('bcc#example.com');
//Attachments
//$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject:localhost';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = ' body in plain text for non-HTML mail lients';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
}
?>
I left the script above as it is and modified php.ini for Xampp in accordance with the comments at Phpmailer not working running from localhost (XAMPP):
[mail function]
SMTP=smtp.kabelmail.de
smtp_port=465
sendmail_from = to#kabelmail.de
sendmail_path ="C:\xampp\sendmail\sendmail.exe\"
;(I also tried sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t" but without success.)
mail.log="C:\xampp\php\logs\php_mail.log"
These are the modifications to sendmail.ini:
[sendmail]
smtp_server=smtp.kabelmail.de
smtp_port=465
smtp_ssl=auto
error_logfile=error.log
debug_logfile=debug.log
auth_username=myname#kabelmail.de
auth_password=mypassword
Results:
1. With the settings above I got this message:
SSL loaded 2018-01-11 12:06:10 SERVER -> CLIENT: 421 4.3.2 Too many open connections.
2018-01-11 12:06:10 CLIENT -> SERVER: EHLO localhost
2018-01-11 12:06:10 SERVER -> CLIENT:
2018-01-11 12:06:10 SMTP ERROR: EHLO command failed:
2018-01-11 12:06:10 SMTP NOTICE: EOF caught while checking if connected
SMTP Error: Could not connect to SMTP host.
SMTP Error: Could not connect to SMTP host.
Message could not be sent.Mailer Error: SMTP Error: Could not connect to SMTP host.
I then replaced $mail->isSendmail(); by $mail->isMail();
The message that showed up now was
SSL loaded Message has been sent
That is what I was looking for, but - there was no message in the mailbox.!!!
php_mail.log had this information, which doesn't look suspicious to me:
[11-Jan-2018 13:09:32 Europe/Berlin] mail() on [C:\xampp\htdocs\to\vendor\PHPMailer\src\PHPMailer.php:768]: To: "name" <myname#kabelmail.de> -- Headers: Date: Thu, 11 Jan 2018 13:09:32 +0100 From: Mailer <from#example.com> Reply-To: Antwort <myname#web.de> Message-ID: <VuAQ3BR022MQyNd3hKCoguqr50Ry9TPG4vIRL2ZmFg#localhost> X-Mailer: PHPMailer 6.0.3 (https://github.com/PHPMailer/PHPMailer) MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="b1_VuAQ3BR022MQyNd3hKCoguqr50Ry9TPG4vIRL2ZmFg" Content-Transfer-Encoding: 8bit
Can somebody give me a hint what might be wrong?
I have been working on that for several days now but obviously I am missing something basic.
--- Edit Jan. 12, 2018 -------------------------------------------------
$mail->isSendmail(); is the setting that is ok on the remote server!
Solved.
The breakthrough was reached when I moved to smtp.web.de.
I now get the the messages from client and server ($mail->SMTPDebug = 2;).
The server still complained about
$mail->setFrom('from#example.com', 'Mailer');
saying
"MAIL FROM command failed: 550-Requested action not taken: mailbox unavailable550 Sender address is not allowed".
Replacing it by
$mail->setFrom('myname#web.de', 'via web.de');
did the job. But not all servers complain about that. Dogado.de for instance does not.
Finally:
$mail->SMTPDebug = 0; // suppresses server and client messages for production use
$mail->CharSet = "UTF-8"; // for correct umlauts
Summary:
The following code can be used on a local machine (Xampp, Netbeans) as well as on a remote server.
<?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
// adjust path accordingly!
require 'vendor/PHPMailer/src/Exception.php';
require 'vendor/PHPMailer/src/PHPMailer.php';
require 'vendor/PHPMailer/src/SMTP.php';
// is ssl loaded? (test only):
//echo (extension_loaded('openssl')?'SSL loaded, ':'SSL not loaded, ')."\n";
$mail = new PHPMailer(true); // Passing `true` enables exceptions
try {
$mail->SMTPDebug = 0; // production use
$mail->isSMTP(); // Set mailer to use SMTP
//=== using web.de ========================================
// adjust settings to your project!
$mail->Host = 'smtp.web.de'; //smtp1.example.com;smtp2.example.com';
// Specify main and backup SMTP servers
$mail->Username = 'myname#web.de'; // SMTP username
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('myname#web.de', 'über web.de'); // required by web.de
$mail->Password = 'mypassword'; // SMTP password
//==========================================================
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
//Recipients
$mail->addAddress('myname#kabelmail.de', 'my name'); // Add a recipient
$mail->addAddress('myname#web.de'); // Name is optional
$mail->CharSet = "UTF-8"; // because of umlauts
//$mail->addCC('cc#example.com');
//$mail->addBCC('bcc#example.com');
//Attachments
//$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
//Content
$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! groß süß ähnlich Ökonom</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients: groß süß ähnlich Ökonom';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
}
Friends I am using xampp software. I have created a database and then a php page. I know how to run the php page by using xampp but when I tried to connect php page with the database, I am getting an error.
Error(Warning: mysql_connect(): Host 'fe80::e15b:3b0:1257:7afe%13' is not allowed to connect to this MySQL server in C:\xampp\htdocs\sant\insert.php on line 4
Could not connect: Host 'fe80::e15b:3b0:1257:7afe%13' is not allowed to connect to this MySQL server).
I am using the hostname as localhost, even I tried with my pc name but that is not working. I have referred lot of sites but didn't get the exact answer.
somebody please help me to overcome this problem
you write code like following
<?php
$host = "localhost"; //your localhost name
$user = "xcode"; //your username
$pass = "xcode"; //your password
$db="xcode"; //your database name
$r = mysql_connect($host, $user, $pass);
if (!$r) {
echo "Could not connect to server\n";
trigger_error(mysql_error(), E_USER_ERROR);
} else {
echo "Connection established\n";
}
echo mysql_get_server_info() . "\n";
$r2 = mysql_select_db($db);
if (!$r2) {
echo "Cannot select database\n";
trigger_error(mysql_error(), E_USER_ERROR);
} else {
echo "database selected\n";
}
mysql_close();
?>
you try this code.
$db = new mysqli('localhost', 'root', '', 'database_name');
if (mysqli_connect_errno()) {
echo 'connect failed: '.mysqli_connect_errno();
} else {
echo 'connected !';
}
Try this and post the result