skip to Main Content

I’m experiencing the following problem:

I Have a small form on my site that pointed to a small php processor to send a mail. There “works” but doesnt send a mail. I tested the script in other hosting and works like a charm.

I called the hosting provider to see where is the problem. The hosting company provided the following PHP script to test the mail sending:

<?php
$to = "[email protected]";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "[email protected]";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>

Now they told me that I do the required editing so it can works. So I did.
I have this small form in the home page (you can see it in pizanoecheveri.co):

<form name="form1" method="post" action="testm/mailing.php" class="miscclass" id="form1">
<div style="text-align: center;" id="contbaloon"><img border="0" alt="" src="/images/misc/baloon1.png"></div>
<input type="text" name="email" class="contactfield" id="textfield">
<p style="text-align: right;"><input type="submit" value="Enviar" name="button" style="background-color: #bbbdc0; border: 0 none; color: #ffffff; margin-bottom: 17px; margin-top: 10px;" class="contacto-x" id="contactbutton"></p>
</form>

And i have done the editings on the code like this:

<?php
$to = "[email protected]";
$subject = "Lista de correos.";
$message = "El siguiente correo se debe agregar a la lista de correo. ".$_POST["email"];
$from = $_POST["email"];
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
echo $message;
?>

I noticed this to the hosting provider and they say that is a problem on the programming. This is something i don’t know sincei tested the same code in other hosting and works perfectly.

In short i don’t understand why the provided code works and when i edit the code doesnt work on THAT HOSTING, when in other it works correctly and there is no syntax error, as far as i see it and Dreamweaver shows it.

The only detail i know from that hosting is that is Windows based running plesk, while the other hosting where i tested the code (where it works) is a Linux based apache. Both are running PHP 5.2.17.

Thanks in Advance

EDIT: i tested the following modification and didn’t worked as well on that hosting

<?php
$to = "[email protected]";
$subject = "Lista de correos.";
$message = "El siguiente correo se debe agregar a la lista de correo. ".$_POST["email"];
$from = $_POST["email"];
#$headers = "From:" . $from;
$headers  = 'MIME-Version: 1.0' . "rn";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "rn";
$headers .= 'From: ' . $from . "rn";
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
echo $message;
?>

2

Answers


  1. Please try this tested code. Just Copy and pest.

    change only header section

    $headers  = 'MIME-Version: 1.0' . "rn";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "rn";
    $headers .= 'From: ' . $from . "rn";
    
    Login or Signup to reply.
  2. The problem is because no Sendmail installed on the host, which is a Linux distributed extension for sending mails via the IMAP protocol.. At modern times, maybe all of the mail providers disable to handle these request because no valid sender needed to handle the request..

    The solution for this is use the SMTP protocol, which validates the sender and the receiver email account as well, so it is slower, but safer..

    You do not need to know how the protocol works, you can use a PHP library to do this, namely the open-source PHPMailer..

    Example

    require_once('class.phpmailer.php');
    
    $mail = new PHPMailer(true);
    $mail->IsSMTP();
    
    try {
        $mail->Host       = "mail.yourdomain.com"; // SMTP server
        $mail->SMTPAuth   = true;                  // enable SMTP authentication
        $mail->Host       = "mail.yourdomain.com"; // sets the SMTP server
        $mail->Port       = 26;                    // set the SMTP port for the GMAIL server
        $mail->Username   = "yourname@yourdomain"; // SMTP account username
        $mail->Password   = "yourpassword";        // SMTP account password
    
        $mail->AddReplyTo('[email protected]', 'First Last');
        $mail->AddAddress('[email protected]', 'John Doe');
        $mail->SetFrom('[email protected]', 'First Last');
    
        $mail->Subject = 'Subject';
        $mail->MsgHTML(file_get_contents('contents.html'));
        $mail->AddAttachment('images/phpmailer.gif');
        $mail->Send();
    
        echo "Message sent!";
    } 
    catch (PHPMailerException $e) {
        echo $e->errorMessage();
    } 
    catch (Exception $e) {
        echo $e->getMessage(); //Boring error messages from anything else!
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search