Drupal 8.5.1安装后报错:调用setRecipients()触发空值错误
Hey fellow Drupal newbie! Let's work through this error you're hitting during your 8.5.1 setup. That Call to a member function setRecipients() on null message means Drupal tried to use an email service that didn't load properly—usually because the server's email configuration is missing or broken. Here are the most straightforward fixes:
1. Test if PHP Can Send Emails
Drupal relies on PHP's built-in mail() function by default. If this isn't set up correctly on your server, the email service will return null, triggering the error.
- Create a simple test file named
test-mail.phpin your website's root folder with this code:<?php $your_email = 'your-real-email@example.com'; $send_test = mail($your_email, 'Drupal Mail Test', 'If you get this, PHP mail is working!'); if ($send_test) { echo "Success! Check your inbox for the test email."; } else { echo "Failed to send mail. Your server's PHP mail settings need fixing."; } ?> - Run this file in your browser. If it fails:
- For Linux servers, make sure the
sendmailpackage is installed and enabled. - For Windows servers, check your
php.inifile to configure SMTP settings (like your email provider's server and port). - If you're using shared hosting, reach out to your provider to confirm email sending is allowed on your plan.
- For Linux servers, make sure the
2. Temporarily Skip the Email Step to Finish Installation
If you just need to get Drupal installed first, you can temporarily disable the problematic code:
- On your server, go to
core/profiles/standard/standard.profile. - Find the line around line 25 in the
standard_form_install_configure_submit()function that handles sending the setup email. It’ll look something like this:$mail_manager->mail('standard', 'install_configure', $form_state->getValue('site_mail'), Language::LANGCODE_SITE_DEFAULT, [], $form_state->getValue('site_mail')); - Comment out this line using
//at the start, like so:// $mail_manager->mail('standard', 'install_configure', $form_state->getValue('site_mail'), Language::LANGCODE_SITE_DEFAULT, [], $form_state->getValue('site_mail')); - Complete the installation process. Once you’re in the Drupal admin, remember to uncomment this line later and fix your email settings.
3. Set Up a Reliable Email Service After Installation
Once Drupal is up and running, fix the email setup properly to avoid future issues:
- Go to Configuration > System > Site information and make sure the "Site email address" is a valid, working email.
- Install the SMTP module (compatible with Drupal 8.5.x) to use an external email service (like Gmail, Outlook, or your hosting provider’s SMTP server). This is way more reliable than PHP’s default
mail()function for most setups.
4. Check Drupal’s Installation Logs for Clues
If the above steps don’t work, look for more details in Drupal’s temporary logs:
- Navigate to
sites/default/files/logson your server. The logs here might show specific errors (like permission issues or missing extensions) that are causing the email service to fail.
内容的提问来源于stack exchange,提问作者WAEX

