0

I have been stuck on this for 2 days now. There were a ton of code available, but not one working solution. Below is my code to send the mail once a user requested a service at an auto repair shop. It updates mysql with all of the data and is then suppose to send the mail.

Although it seems that something is happening (apart from the data insertion), it does not send the mail at all. Any help will be appreciated, thanks

<?php
//Get mail smtp from files...
include('smtpconfig.php');
include('smtpclass.php');

//Get connection...
require ("connection.php");

//Form data...
if (!isset($_POST['booking']))
{
    $_POST['booking'] = "undefine";
}
$booking = strip_tags($_POST['booking']); //This is my submit button...
$name = strtolower(strip_tags($_POST['name']));
$surname = strtolower(strip_tags($_POST['surname']));
$cell = strip_tags($_POST['cell']);
$worktel = strip_tags($_POST['worktel']);
$email = strip_tags($_POST['email']);
$vehmake = strip_tags($_POST['vehmake']);
$vehmodel = strip_tags($_POST['vehmodel']);
$vehyear = strip_tags($_POST["vehyear"]);
$regnum = strip_tags($_POST['regnum']);
$mileage = strip_tags($_POST['mileage']);
$daterequested = strip_tags(date("Y-m-d"));
$typebook = strip_tags($_POST['typebook']);
$addrepairs = strip_tags($_POST['addrepairs']);

if ($booking) //This is my submit button...
{
  //Do validation of entries...
  if ($name&&$surname&&$cell&&$worktel&&$email&&$vehmake&&$vehmodel&&$vehyear&&$regnum&&$mileage&&$typebook&&$addrepairs)
    {
            //Register booking...
            //Do database connection...

            $querryreglogin = mysql_query("INSERT INTO bookings (id, name, surname, cell, worktel, email, vehmake, vehmodel, vehyear, regnum, mileage, daterequested, typebook, addrepairs) VALUES ('', '$name', '$surname', '$cell', '$worktel', '$email', '$vehmake', '$vehmodel', '$vehyear', '$regnum', '$mileage', '$daterequested', '$typebook', '$addrepairs')");

      if($_SERVER["REQUEST_METHOD"] == "POST")
      {
      $to = "bookings@gmservicecentre.co.za"; //the smtp server
      $from = $email;
      $subject = "Service Booking Request";
      $body = $name ." " . $surname ." wishes to confirm a date for a " . $typebook ." on their " . $vehyear .", " . $vehmake .", " . $vehmodel ."with" . $mileage ." kilometres and " . $regnum .". They also require " . $addrepairs ." additional work to be carried out. The can be contacted on - Cellphone Number " . $cell .", Work Telephone Number " . $worktel ." or on their e-mail address at " . $email;
      $SMTPMail = new SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body);
      $SMTPChat = $SMTPMail->SendMail();
      }

              echo("<script type='text/javascript'>window.alert('Thank you for making a booking with us. Prescilla will confirm your date and time of the booking soon.')</script>");
              echo("<a href=\'index.php'>Click Here If You Are Not Re-directed Automatically</a>");
              echo("<script type='text/javascript'>location.replace('index.php');</script>"); //I get the message and I get redirected to index.php, no message though...
    }
      else
        echo "<script type='text/javascript'>window.alert('Please complete ALL required fields (marked with red exclamation image).')</script>";
}
?>

smtpconfig file code

<?php
//Server Address
//$SmtpServer="mail.gmservicecentre.co.za";
$SmtpServer="pop3.gmservicecentre.co.za";
$SmtpPort="110"; //default
$SmtpUser="*****";
$SmtpPass="******";
?>

The smtpclass file code

<?php
class SMTPClient
{

function SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body)
{

$this->SmtpServer = $SmtpServer;
$this->SmtpUser = base64_encode ($SmtpUser);
$this->SmtpPass = base64_encode ($SmtpPass);
$this->from = $from;
$this->to = $to;
$this->subject = $subject;
$this->body = $body;

if ($SmtpPort == "")
{
$this->PortSMTP = 110;
}
else
{
$this->PortSMTP = $SmtpPort;
}
}

function SendMail ()
{
if ($SMTPIN = fsockopen ($this->SmtpServer, $this->PortSMTP))
{
fputs ($SMTPIN, "EHLO ".$HTTP_HOST."\r\n");
$talk["hello"] = fgets ( $SMTPIN, 1024 );
fputs($SMTPIN, "auth login\r\n");
$talk["res"]=fgets($SMTPIN,1024);
fputs($SMTPIN, $this->SmtpUser."\r\n");
$talk["user"]=fgets($SMTPIN,1024);
fputs($SMTPIN, $this->SmtpPass."\r\n");
$talk["pass"]=fgets($SMTPIN,256);
fputs ($SMTPIN, "MAIL FROM: <".$this->from.">\r\n");
$talk["From"] = fgets ( $SMTPIN, 1024 );
fputs ($SMTPIN, "RCPT TO: <".$this->to.">\r\n");
$talk["To"] = fgets ($SMTPIN, 1024);
fputs($SMTPIN, "DATA\r\n");
$talk["data"]=fgets( $SMTPIN,1024 );
fputs($SMTPIN, "To: <".$this->to.">\r\nFrom: <".$this->from.">\r\nSubject:".$this->subject."\r\n\r\n\r\n".$this->body."\r\n.\r\n");
$talk["send"]=fgets($SMTPIN,256);
//CLOSE CONNECTION AND EXIT ...
fputs ($SMTPIN, "QUIT\r\n");
fclose($SMTPIN);
//
}
return $talk;
}
}
?>

Edited by AndreRet: n/a

3
Contributors
6
Replies
7
Views
6 Years
Discussion Span
Last Post by AndreRet
1

SOrry didn't read it thoroughly, but are you on local or remote?
If remote, check that your host doesn't insist on a -f flag or similar in your header. Have a look at the host FAQs w.r.t. sending mail. That blew me sideways for days with my previous host.

Votes + Comments
Thanks for the help...
0

Thanks ardav. I was first running it on localhost and thought fine, maybe the problem here. After I uploaded all to the host, still the same, no error is returned but still no email either.

I will check their recommendations and will post back here a bit later.

0

OK. Try a simple mail() post to yourself.
Try different sender address - own domain and made up domain.
The made up domain *should* be blocked by your host.
If your domain-based address is also blocked, check that you don't need certain additional headers or flags (as prev. mentioned).

BTW - localhost prob. won't work unless you have an smtp server.

0

Thanks both of you. The culprit was port 110. I have changed it to 25 and all sorted, thanks.:)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.