codeigniter customer contact form - codeigniter

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

Related

Swiftmailer Symfony 3 : 1 email sent but nothing appear

I'm trying to send an email with symfony 3, swiftmailer and twig.
I'm doing a form with formbuilder and when someone click on the submit button, it send the mail. I don't have an error, only a "1 spooled message".
What I've tried : I did : php bin/console swiftmailer:email:send
It returns : [OK] 1 emails were successfully sent. (also here i've no mail).
In my two boxes I have allowed less restrictions for connexions.
My code looks like :
For the controller :
/**
* #Route("testmail", name="testmail")
*/
public function testmail(Request $request)
{
$societe = null;
$form = $this->createFormBuilder()
->add('Societe', TextType::class, array('label' => 'Société'), array('constraints' => array(new NotBlank(array()),
new Length(array('min' => 2,
'max' => 25)))))
-> add('send',SubmitType::class, array('label' => 'Cotation'))
->getForm();
$form->handleRequest($request);
if ($form->isValid()) {
if ($request->isMethod('POST')) {
$societe = $form["Societe"]->getData();
$message = \Swift_Message::newInstance()
->setSubject('Etude Financiere')
->setFrom('wolffvianney#gmail.com')
->setTo('vianney.wolff#yahoo.fr')
->setCharset('utf-8')
->setContentType('text/html')
->setBody($this->render('#gkeep/Finance/email.html.twig', array('Societe' => $societe)));
$this->get('mailer')->send($message);
}
}
return $this->render('#gkeep/Finance/finance.html.twig', array('form' =>$form->createView(),
'Societe'=>$societe));
}
the config.yml :
swiftmailer:
transport: '%mailer_transport%'
host: '%mailer_host%'
username: '%mailer_user%'
password: '%mailer_password%'
spool: { type: memory }
the parameters.yml :
mailer_transport: mail
mailer_host: smtp.gmail.com
mailer_user: wolffvianney#gmail.com
mailer_password: *mypasswordforwolffvianney#gmail.com*
secret: thesecret
the Finance/email.html.twig
<html>
hi
société : {{ Societe }}
</html>
if anyone has any advices or help, I can send other files if needed. I don't understand what is wrong, thanks for advance. (I also tried to delete the line spool{type:memory
it says then that 1 email has been sent but here also, I don't receive any mails.
Vianney
Try
php bin/console swiftmailer:spool:send --env={your_env}

PHPMailer not running with Xampp on Windows10

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;
}

Symfony confirmation email not send but gmail work

i have some probleme using swiftmailer for setting my confirmation email, normaly everything is set well, but the mail is not sent, and i have my user in my database (but enable is set to 0 of course).
Since i don't have errors show by symfony i suppose it's my gmail account that blocked them, but i already set it to allow other application to use it as a "server", and i have a page that use swiftmailer to send normal mail, and it work fine.
i'm lost, thanks for your future help
My config.yml :
swiftmailer:
transport: %mailer_transport%
host: %mailer_host%
username: %mailer_user%
password: %mailer_password%
encryption: ssl
fos_user:
db_driver: orm
firewall_name: main
user_class: UserBundle\Entity\User
service:
mailer: fos_user.mailer.default
registration:
confirmation:
enabled: true
from_email:
address: maxime.duvey#gmail.com
sender_name: Registration mail
My config.yml :
mailer_transport: gmail
mailer_host: 127.0.0.1
mailer_user: maxime.duvey#gmail.com
mailer_password: XXXXXXXXXXX
i'm really lost, i don't understand why it don't work
It might be because you have to turn on "Less Secure Apps" as gmail allows doesn't allow you to access logins unless it is a secure app that they provide. This can be found in you google admin console.
See the link here for more info
I had the same problem when using PHPMailer.
However if you do decide to turn it on, it is not recommended.
They mention this in the link provided.
now that i think of it, it's maybe my manner to add a new user to my database :
my controler :
$userregister = new User();
$formregister = $this->get('form.factory')->createBuilder(FormType::class, $userregister);
$formregister
->add('firstname', TextType::class)
->add('lastname', TextType::class)
->add('email', EmailType::class)
->add('phonehome', NumberType::class)
->add('phoneportable', NumberType::class)
->add('username', TextType::class)
//->add('Password', PasswordType::class)
->add('plainPassword', RepeatedType::class, array(
'type' => PasswordType::class,
'first_options' => array('label' => 'Password'),
'second_options' => array('label' => 'Repeat Password'),
))
->add('submit', SubmitType::class);
$form = $formregister->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid())
{
$em = $this->getDoctrine()->getManager();
$em->persist($userregister);
$em->flush();
$request->getSession()->getFlashBag()->add('notice', 'Annonce bien enregistrée.');
return $this->redirect($this->generateUrl('Contact_Action', array('id' => $userregister->getId())));
}
return $this->render('register.html.twig', array('form'=>$form->createView()));
and my twig :
{{ form(form) }}
i'm not sure, maybe

yandex smtp doesnt work on codeigniter(digitalocean+ubuntu+serverpilot)

I send email on localhost but doesnt work same settings on server(digitalocean+serverpilot).
php's open ssl support is enabled.
php get "Message: fsockopen(): unable to connect to
ssl://smtp.yandex.com.tr:465 (Connection timed out)
codeigniter framework get :
The following SMTP error was encountered: 110 Connection timed out
Unable to send email using PHP SMTP. Your server might not be
configured to send mail using this method.
my code is:
$config = Array('protocol' => 'smtp','smtp_host' => 'ssl://smtp.yandex.com.tr','smtp_port' => 465, 'smtp_user' => 'info#mydomain.com','smtp_pass' => 'mypass','mailtype' => 'html', 'charset' => 'utf-8');
$this->load->library('email');
$this->email->initialize($config);
$this->email->set_newline("\r\n");
$this->email->from('info#mydomain.com', 'test.com');
$this->email->to('testing#yandex.com');
$this->email->subject('test');
$this->email->message('test body');
$this->email->send();
echo $this->email->print_debugger();
nslookup smtp.yandex.com:
Server: 2001:4860:4860::8844 Address: 2001:4860:4860::8844#53
Non-authoritative answer: smtp.yandex.com canonical name =
smtp.yandex.ru. Name: smtp.yandex.ru Address: 93.158.134.38
Name: smtp.yandex.ru Address: 87.250.250.38 Name: smtp.yandex.ru
Address: 213.180.204.38 Name: smtp.yandex.ru Address: 213.180.193.38
Name: smtp.yandex.ru Address: 77.88.21.38
and telnet request is work.
Your outgoing connection may be blocked by a firewall.
Use tool like tcptraceroute to locate the problem.

Failed to connect to mailserver in CodeIgniter

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!

Resources