The cart is empty

Sending emails using PHP is a common task in Web development. One of the main ways to achieve this is by using the mail() function in PHP. However, there are instances where the standard port setting for sending emails using this function might not suffice. In some cases, it's necessary to use an alternative port, such as port 587, to avoid delivery issues.

Here's a simple PHP script that allows you to send emails via PHP mail using port 587:

<?php
// Recipient's email address
$to = "This email address is being protected from spambots. You need JavaScript enabled to view it.";

// Email subject
$subject = "Test Email";

// Email message content
$message = "This is a test email sent using PHP.";

// Email headers
$headers = "From: This email address is being protected from spambots. You need JavaScript enabled to view it.\r\n";
$headers .= "Reply-To: This email address is being protected from spambots. You need JavaScript enabled to view it.\r\n";
$headers .= "Content-Type: text/plain; charset=UTF-8\r\n";

// Set parameters for sending email using port 587
ini_set("SMTP", "smtp.example.com");
ini_set("smtp_port", "587");

// Attempt to send the email
if (mail($to, $subject, $message, $headers)) {
    echo "Email was successfully sent.";
} else {
    echo "Failed to send email.";
}
?>

This script begins by defining variables containing the recipient's email address, the email subject, and the message content. Next, email headers are set, including the sender and content type. It's crucial that parameters for the SMTP server and port are also set. Finally, the mail() function is used to send the email.

If the script is successful, it will display the message "Email was successfully sent." Otherwise, it will display "Failed to send email." This way, you can easily test sending emails using a PHP script using port 587.