John Davidson

php - how to make sender's address dynamic using email notification in laravel

0 comments
Message:


I have a project on laravel 5.5 my email notification is working fine but I want the sender address to be picked from the database not hand-coded from notifiable.


public function toMail($notifiable)
{
return (new MailMessage)
->from('[email protected]', 'Example')
->line('The introduction to the notification.')
->action('Notification Action', url('/'))
->line('Thank you for using our application!');
}

my mailtrap mail


scrrenshot



My Answer:
To create a sender in PHP, you can use the `mail()` function. Here is an example of how to create a simple sender in PHP:

php
$to = "[email protected]";
$subject = "Test Email";
$message = "This is a test email from PHP";

$headers = "From: [email protected]\r\n";
$headers .= "Reply-To: [email protected]\r\n";
$headers .= "X-Mailer: PHP/" . phpversion();

// Send the email
$mail_sent = mail($to, $subject, $message, $headers);

if ($mail_sent) {
echo "Email sent successfully";
} else {
echo "Email sending failed";
}


In this example, replace `[email protected]` with the email address of the recipient and `[email protected]` with the email address of the sender. You can also customize the subject and message of the email as needed.

Make sure that your server is properly configured to send emails using the `mail()` function. You may need to set up an SMTP server or configure the `php.ini` file to specify the SMTP server settings.

Rate this post

3 of 5 based on 2995 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us