As with many hosting companies, the phpmail() function is disabled in our company as well. The reason for keeping this function disabled is that mail can be sent directly
without any authentication in the phpmail() function. If mail is sent without authentication, it is impossible to prevent spam mail sending. To prevent spam mails and IP addresses from being added to blacklists, the mail() and phpmail() functions must be kept disabled
on servers and mail must be sent via SMTP.
Now let’s cover how to send mail using SMTP connection via PHP. For this, we will use the PHPMailer library.
You can download the PHPMailer library here.
We upload the class.phpmailer.php, class.smtp.php, and class.pop3.php files from the downloaded library to the same directory as our mail form.
Our mail form code:
require(“class.phpmailer.php”);
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true;
$mail->SMTPSecure = ‘ssl’;
// For secure connection use ssl, for normal connection use tls.
$mail->Host = “mail.siteismi.com”; // Mail server name must be entered.
$mail->Port = 465; // 465 for secure connection, 587 for normal connection
$mail->IsHTML(true);
$mail->SetLanguage(“tr”, “phpmailer/language”);
$mail->CharSet =“utf-8”;
$mail->Username = “isim@siteismi.com”; // Username of our mail address
$mail->Password = “PASSWORD”; // Password of our mail address
$mail->SetFrom(“isim@siteismi.com”, “Isim”); // Name displayed when mail is sent
$mail->AddAddress(“ahmetmakal@msn.com”); // Recipient address
$mail->Subject = “Mesaj Basligi”; // Subject heading
$mail->Body = “Mesaj icerigi”; // Mail
content
if(!$mail->Send()){
echo “Mailer Error: “.$mail->ErrorInfo;
} else {
echo “Mesaj gonderildi”;
}
I wrote the fields that need to be filled in as comments after the code above. With the above settings, you can send
mail without issues using your server’s SMTP service.
Now let’s see the necessary settings for Gmail and Yandex, which provide free mail service.
Yandex SMTP Settings:
$mail->SMTPSecure = ‘tls’;
$mail->Host = ‘smtp.yandex.com’;
$mail->Port = 587;Gmail SMTP Settings:
$mail->SMTPSecure = ‘ssl’;
$mail->Host =
‘smtp.gmail.com’;
$mail->Port = 465;SMTP Mail Settings for Ready-Made Scripts
Now let’s cover how SMTP settings should be configured for ready-made software. Some ready-made software includes the PHPMailer library running in the
background. You can also configure SMTP settings from the interface of the software you use. Below are the settings for some software as examples.
For WordPress, we need to install the WP Mail SMTP
plugin.
Apply the following settings from Settings > Email.
From Email: isim@siteismi.com
From Name: Name
Mailer: Send all WordPress emails via SMTP.
SMTP Host: localhost or server hostname (you can learn
the hostname from us)
SMTP Port: 465
Encryption: Use SSL encryption.
Authentication: Yes: Use SMTP authentication.
Username: isim@siteismi.com
Password: mailpasswordSMTP Settings for vBulletin:
vBulletin Options > E-Mail Settings
From here, select Send emails via SMTP Server.
SMTP Server: mail.siteadresiniz.com
SMTP Port: 465
SMTP Username: isim@siteismi.com
SMTP Password: Your email address password
Guaranteed connection to SMTP Server: SSL
SMTP Settings for SMF:
To access settings, go to Admin Panel > Maintenance > Email.
Email Type: SMTP
SMTP Server: ssl://localhost or
ssl://mail.siteadresiniz.com
SMTP Port: 465
SMTP Username: isim@siteismi.com
SMTP Password: Your email address passwordSMTP Settings for OpenCart:
To access settings, go to System
> Settings > Mail.
Mail Protocol: SMTP
SMTP Host: ssl://localhost or ssl://mail.siteadresiniz.com
SMTP Username: isim@siteismi.com
SMTP Password: Your email address password
SMTP Port: 465Each software has its own SMTP
settings. Based on the examples above, you can easily configure the SMTP mail settings for the software you use.
Leave a Comment
* Your comment will be published after approval.
Comments
0No comments yet. Be the first to comment!