0

I'm trying to get a contact form on a web page to work after the web host stopped supporting the PHP-version it was built for. For some reason I can't get the email to send and I can't for the life of me figure out whats wrong with the code!

Using Chrome to monitor the network traffic I get the error message that is added to the block below.

{success: false, error: "Kunde inte skicka e-postmeddelande"} ("Unable to send email")

Here is the block that send the email:

$to = $form['email']['to'];
    $subject = $form['subject'];
    $message = get_email_body($subject, $form['heading'], $form['fields'], $form['resources']);
    $headers = get_email_headers($to, $form_email); 

    $sent = @mail($to, $subject, $message, $headers);

    if(!$sent)
        die(get_form_error_response($form['resources']['failed_to_send_email']));

    $success_data = array(
        'redirect' => $form['success_redirect']
    );

Since I can't find any errors in the code I'm stuck. If anyone can see anything I can't, or maybe point me to where to look next I'd be eternally grateful!

  • 2
    remove the **@** in `@mail(` because it prevents showing any `errors/warnings`. – Roy Bogado Feb 26 '20 at 08:05
  • I removed it. The browser is still just saying "Server encountered an error", and looking at network traffic it's the same as before. – Arvid Wretman Feb 26 '20 at 08:09
  • Are you sure your `get_email_body()` or `get_email_headers()` return the correct data in the correct format? You need to post that as well or we won't have a clue what you're actually passing in to the mail-function. – M. Eriksson Feb 26 '20 at 08:09
  • _"The browser is still just saying "Server encountered an error","_ - What do you mean by "still"? This is the first time you've mentioned that error message. Check the web servers error log and check if it has some more info. – M. Eriksson Feb 26 '20 at 08:12
  • Okey I found the issue was with our email-provider. It's solved. thanks for all your help! – Arvid Wretman Feb 26 '20 at 08:32

0 Answers0