What are common SMTP issues when sending emails through PHP forms?
Common SMTP issues when sending emails through PHP forms include incorrect SMTP server settings, authentication problems, and firewall restrictions blocking outgoing emails. To solve these issues, double-check the SMTP server settings, ensure that the authentication credentials are correct, and make sure that the firewall allows outgoing SMTP connections.
<?php
// Set SMTP server settings
ini_set('SMTP', 'smtp.example.com');
ini_set('smtp_port', 25);
// Set authentication credentials
ini_set('sendmail_from', 'your_email@example.com');
ini_set('sendmail_path', '/usr/sbin/sendmail -t -i -fyour_email@example.com');
// Send email using PHP mail function
$to = 'recipient@example.com';
$subject = 'Test Email';
$message = 'This is a test email sent through PHP.';
$headers = 'From: your_email@example.com';
mail($to, $subject, $message, $headers);
?>