How can one specify a mail server and port using ini_set() in PHP for sending emails?
To specify a mail server and port using ini_set() in PHP for sending emails, you can set the 'SMTP' and 'smtp_port' configuration options. This allows you to define the SMTP server address and port number for sending emails from your PHP script.
// Specify the mail server and port for sending emails
ini_set('SMTP', 'mail.example.com');
ini_set('smtp_port', 25);
// Now you can use the mail() function to send emails
$to = 'recipient@example.com';
$subject = 'Test Email';
$message = 'This is a test email sent from PHP';
$headers = 'From: sender@example.com';
mail($to, $subject, $message, $headers);
Keywords
Related Questions
- Can PHP be used to round numbers to specific fractions, such as quarters, without losing precision?
- How can I efficiently collect and pass multiple rows of data from a database to a view in PHP?
- Are there any best practices for handling imap_header() function in PHP to prevent header disappearance after a page reload?