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
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 = "recipient@example.com";
$subject = "Test Email";
$message = "This is a test email from PHP";
$headers = "From: sender@example.com\r\n";
$headers .= "Reply-To: sender@example.com\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 `recipient@example.com` with the email address of the recipient and `sender@example.com` 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 3477 votesComments