note 129090 added to function.mail

From: Date: Wed, 06 Dec 2023 11:21:25 +0000
Subject: note 129090 added to function.mail
Groups: php.notes 
Request: Send a blank email to php-notes+get-221044@lists.php.net to get a copy of this message
Sending mail using XAMPP server I encountered numerous issues while attempting to send emails using the XAMPP server. However, I eventually found the correct method to accomplish it. Configuring PHP's mail functionality to work with Gmail's SMTP server involves editing the php.ini and sendmail.ini configuration files. Below are the formal steps for setting up PHP to send emails through Gmail's SMTP server using XAMPP: Configuring php.ini: 1. Open php.ini in an editor: Open the php.ini configuration file in your preferred text editor. 2. Locate the mail function: Use the search function (Ctrl + F) to find the section related to the mail function within the php.ini file. 3. Update mail function settings: Copy and paste the following configuration parameters into the mail function section. Comment out or disable all other settings related to mail. php.ini code to be edited: SMTP=smtp.gmail.com smtp_port=587 sendmail_from = yourmail@gmail.com sendmail_path = write_sendmail.exe_path 4. Save the changes: Save the php.ini file after applying the modifications. Configuring sendmail.ini (in XAMPP folder): 1. Open sendmail.ini in XAMPP folder: Locate and open the sendmail.ini configuration file within the XAMPP directory. 2. Adjust SMTP settings: Insert the following content into the sendmail.ini file, marking other configurations as comments: sendmail.ini code : smtp_server=smtp.gmail.com smtp_port=587 error_logfile=error.log debug_logfile=debug.log auth_username=yourmail@gmail.com auth_password=app_password_after_enabling_two_factor_authentication_for_your_mail_id force_sender=priyansh.kala.4@gmail.com 3. Save the changes: Save the sendmail.ini file after inserting the specified configurations. These steps configure PHP to utilize Gmail's SMTP server for sending emails. Ensure that the modifications are saved and that the necessary XAMPP services are restarted for the changes to take effect. Please note that using hardcoded passwords in configuration files poses a security risk. Storing passwords directly in plain text files should be avoided in production environments. Consider using environment variables or secure credential management systems for better security practices. Code for sending mail-: <?php $subject = "Mail for checking"; $msg = "Hey! Let us play with PHP."; $receiver = "reciever@gmail.com"; mail($receiver, $subject, $msg); ?> ---- Server IP: 45.112.84.4 Probable Submitter: 45.91.157.134 (proxied: 2401:4900:55a2:65f7:2052:8fe5:a1bb:c23e) ---- Manual Page -- https://php.net/manual/en/function.mail.php Edit -- https://main.php.net/note/edit/129090 Del: integrated -- https://main.php.net/note/delete/129090/integrated Del: useless -- https://main.php.net/note/delete/129090/useless Del: bad code -- https://main.php.net/note/delete/129090/bad+code Del: spam -- https://main.php.net/note/delete/129090/spam Del: non-english -- https://main.php.net/note/delete/129090/non-english Del: in docs -- https://main.php.net/note/delete/129090/in+docs Del: other reasons-- https://main.php.net/note/delete/129090 Reject -- https://main.php.net/note/reject/129090 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#221044) next »