Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8634529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:44:49+00:00 2026-06-12T09:44:49+00:00

I have a problem with my PHP Mail. It stops working from time to

  • 0

I have a problem with my PHP Mail. It stops working from time to time without me even touching the code. I have a script which checks if required forms are empty. This script works. But if I fill in all the required fields I should get a text which says "Your mail was successfully sent" but I don’t. But if I edit my code by just moving a bit of text some lines down and back to the original position again it works, for a while. It’s often under the night it stops working. Can it be the server that is causing trouble or is it my code that I posted below?

<?php

if(isset($_POST['submit'])){

$namn = strip_tags($_POST['namn']);
$foretag = strip_tags($_POST['foretag']);
$adress = strip_tags($_POST['adress']);
$postnr = strip_tags($_POST['postnr']);
$ort = strip_tags($_POST['ort']);
$telefon = strip_tags($_POST['telefon']);
$epost = strip_tags($_POST['epost']);
$meddelande = strip_tags($_POST['meddelande']);

function check_required_fields($required_array){
    $field_errors = array();
    foreach($required_array as $fieldname){
        if ((!isset($_POST[$fieldname])) || (empty($_POST[$fieldname]))){ 
            if($_POST[$fieldname] != '0'){
                $field_errors[] = $fieldname; 
            }
        }
    }
    return $field_errors;
}

$errors = array();
$required_fields = array('namn', 'telefon', 'meddelande');
$errors = array_merge($errors, check_required_fields($required_fields));

if(empty($errors)){

$meddelande=nl2br($meddelande);

if(empty($foretag)){ $foretag='-'; }
if(empty($adress)){ $adress='-'; }
if(empty($postnr)){ $postnr='-'; }
if(empty($ort)){ $ort='-'; }
if(empty($epost)){ $epost='-'; }

$body = 
"
Namn: <b>". $namn ."</b><br />
Företag: <b>". $foretag ."</b><br />
Adress: <b>". $adress ."</b><br />
Postnr: <b>". $postnr ."</b><br />
Ort: <b>". $ort ."</b><br />
Telefon: <b>". $telefon ."</b><br />
E-post: <b>". $epost ."</b><br /><br />
Meddelande: <b><br />". $meddelande
;

$headers = "From: $namn <webmaster@allflytt.com>\r\n";
$headers .= "Content-type: text/html; charset=utf-8\r\n";
$headers .= "X-Mailer: PHP v".phpversion();

$success = mail('info@allflytt.com', 'Meddelande', $body, $headers);

}

}

?>

    <form method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
    
            <?php
                if(!empty($errors)){
                    echo "<p class=\"field_error\">De rödmarkerade fälten måste fyllas i.</p>";
                }
            ?>
            
            <?php
                if(empty($errors) && $success){
                    echo "<p class=\"p_success\">Tack för ditt meddelande! Vi kommer att besvara det inom kort.</p>";
                }
            ?>
    
    <p>
        <label for="namn">
        <?php if(!empty($errors)){if(in_array("namn", $errors)){echo "<span class=\"field_error\">";}}?>Namn: *<?php if(!empty($errors)){if(in_array("namn", $errors)){echo "</span>";}} ?>
        </label><br />
        <input type="text" name="namn" id="namn" class="text" tabindex="15" value="<?php if(!empty($errors)){ echo $namn; } ?>" />
            <br />
        <label for="foretag">Företag:</label><br />
        <input type="text" name="foretag" id="foretag" class="text" tabindex="20" value="<?php if(!empty($errors)){ echo $foretag; }?>" />
            <br />
        <label for="adress">Adress:</label><br />
        <input type="text" name="adress" id="adress" class="text" tabindex="30" value="<?php if(!empty($errors)){ echo $adress; } ?>" />
            <br />
        <label for="postnr">Postnummer:</label><br />
        <input type="text" name="postnr" id="postnr" class="text_medium" tabindex="40" value="<?php if(!empty($errors)){ echo $postnr; } ?>" />
            <br />
        <label for="ort">Ort:</label><br />
        <input type="text" name="ort" id="ort" class="text" tabindex="50" value="<?php if(!empty($errors)){ echo $ort; } ?>" />
            <br />
        <label for="telefon">
        <?php if(!empty($errors)){if(in_array("telefon", $errors)){echo "<span class=\"field_error\">";}}?>Telefon: *<?php if(!empty($errors)){if(in_array("telefon", $errors)){echo "</span>";}} ?>
        </label><br />              
        <input type="text" name="telefon" id="telefon" class="text" tabindex="60" value="<?php if(!empty($errors)){ echo $telefon; } ?>" />
            <br />
        <label for="epost">E-post:</label><br />                
        <input type="text" name="epost" id="epost" class="text" tabindex="70" value="<?php if(!empty($errors)){ echo $epost; } ?>" />
            <br />
        <label for="meddelande">
        <?php if(!empty($errors)){if(in_array("meddelande", $errors)){echo "<span class=\"field_error\">";}}?>Meddelande: *<?php if(!empty($errors)){if(in_array("meddelande", $errors)){echo "</span>";}} ?>
        </label><br />              
        <textarea name="meddelande" id="meddelande" class="textarea" tabindex="80"><?php if(!empty($errors)){ echo $meddelande; } ?></textarea>
            <br />  
        <input type="submit" name="submit" value="Skicka" class="submit" />
    </p>

    </form>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T09:44:50+00:00Added an answer on June 12, 2026 at 9:44 am

    Problem solved. Changed to a new server host. No issues any more!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a basic PHP mail() script which e-mails users the details of a
in my form i have this code <form action=mail.php class=contactForm name=cform method=post> Problem is
I have problem with php script. The thing is that it shows me, that
I have a problem in php code inserting values into database (I use PHPMyAdmin).
I have a bizzare problem with php date function. code: $numDays = 8; $date
i have a problem using some php functions on a string i get from
i am new in php i have a problem in my php code.please help
I have various emails being sent out via PHP mail. The problem is, for
I have a PHP mail script that successfully sends emails to everything BUT GMail
I have a problem with my code in php. I would like to delete

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.