Configure SMTP data for php mail () function

I searched for an answer and tried this problem many times.

My script works fine on my web host, but when migrating to another dedicated server, mail is never delivered. Now I need to install the SMTP server, but it will not work.

Using Gmail applications. This is what the code looks like.

<?php if(!$_POST) exit; $email = $_POST['email']; //$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[AZ]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS'; if(!eregi("@",$email )){ $error.="Invalid email address entered"; $errors=1; } if($errors==1) echo $error; else{ $values = array ('name','email','telephone','message'); $required = array('name','email','telephone','message'); $your_email = "xxx@example.com"; $email_subject = "New Messag: ".$_POST['subject']; $email_content = "New message:\n"; foreach($values as $key => $value){ if(in_array($value,$required)){ if ($key != 'subject' && $key != 'telephone') { if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; } } $email_content .= $value.': '.$_POST[$value]."\n"; } } if(@mail($your_email,$email_subject,$email_content)) { echo 'Message sent!'; } else { echo 'ERROR!'; } } $mail->Mailer = "smtp"; $mail->Host = "ssl://smtp.gmail.com"; $mail->Port = 465; $mail->SMTPAuth = true; // turn on SMTP authentication $mail->Username = "user@gmail.com"; // SMTP username $mail->Password = "password"; // SMTP password ?> 

So, how to configure SMTP settings correctly?

+8
php email smtp
source share
3 answers

Windows only:. You can try using the ini_set() Docs function for SMTP Documents and smtp_port Documents :

 ini_set('SMTP', 'mysmtphost'); ini_set('smtp_port', 25); 
+6
source share

Check your php.ini, you can set these values ​​there.

Here's the description in the php reference: http://php.net/manual/en/mail.configuration.php

If you want to use several different SMTP servers in your application, I recommend using a "larger" mail infrastructure, page Swiftmailer

+1
source share

Try using a dedicated telnet server for smtp.gmail.com on port 465. It may be blocked by your ISP.

0
source share

All Articles