Is the problem with hosting server or me?

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
hanzi
Forum Newbie
Posts: 3
Joined: Mon Aug 18, 2008 7:38 am

Is the problem with hosting server or me?

Post by hanzi »

Hi :?:

I did the tutorial on mailing from an html form with swift3.3.3 and uploaded all to my server like instructed. All the errors work, like invalid email and such but when I click submit it just jumps to a blank screen, I also don't receive any emails so that tells me that its not working correctly.

Can someone have a look at what I've done and tell me if the fault is with me or should I contact my hosting company and clear it up with them.

My first time using PHP so I don't have a clue?
Thanx in advance


this is the handle_form.php

Code: Select all

<?php
 
//Check if the required fields were sent
// Redirect back to the form if not
if (empty($_POST["name"]) || empty($_POST["email"]) || empty($_POST["id"])
    || empty($_POST["contact1"]) || empty($_POST["us"]))
{
    //redirect back to form
    header("Location: ./registerCourse.php?error=not_enough_info"); //This should really be an absolute URL if you know it
    exit();
}
 
//Copy into global variables
$name = $_POST["name"];
$surname = $_POST["surname"];
$email = $_POST["email"];
$title = $_POST["title"];
$id = $_POST["id"];
$postalAd = $_POST["postal"];
$individual = $_POST["individual"];
$group = $_POST["group"];
$contactNumber1 = $_POST["contact1"];
$contactNumber2 = $_POST["contact2"];
$numberStudents = $_POST["numberS"];
$organisation = $_POST["organisation"];
$unitStandard = $_POST["us"];
 
 
//Validate the email address using a regex (I suggest you use a better one than this!!)
if (!preg_match("/[a-zA-Z0-9_\\.-]+@[a-zA-Z0-9_\\.-]+/", $email))
{
    header("Location: ./registerCourse.php?error=invalid_email");
    exit();
}
 
 
//Everything looks ok, we can start Swift
 
require_once "lib/Swift.php";
require_once "lib/Swift/Connection/SMTP.php";
 
//Enable disk caching if we can
if (is_writable("/tmp"))
{
    Swift_CacheFactory::setClassName("Swift_Cache_Disk");
    Swift_Cache_Disk::setSavePath("/tmp");
}
 
//Create a Swift instance
$swift =& new Swift(new Swift_Connection_SMTP("mail.mentornet.co.za"));
 
//Create the sender from the details we've been given
$sender =& new Swift_Address($email, $title, $name, $surname);
 
//Create the message to send
$message =& new Swift_Message("New Registration: " . $id);
$message->attach(new Swift_Message_Part($contactNumber1, contactNumber2, $organisation, $numberStudents, $group, $individual, $postalAd));
 
 
//Try sending the email
$sent = $swift->send($message, "tech@mentornet.co.za", $sender);
//Disconnect from SMTP, we're done
$swift->disconnect();
 
if ($sent)
{
    header("Location:registrationComplete.html");
    exit();
}
else
{
    header("Location:registerCourse.php?error=sending_failed");
    exit();
}
this is the registerCourse.php

Code: Select all

<?php
 
//Display an error if something went wrong
if (!empty($_GET["error"]))
{
    switch ($_GET["error"])
    {
        case "not_enough_info":
            header("Location:errorPage.html");
            break;
        case "invalid_email":
            header("Location:errorMail.html");
            break;
        case "sending_failed":
            header("Location:errorSend.html");
            break;
    }
}
 
?>
 
<html>
    <head>
        <title>Mentornet Online - Register for Courses</title>
        <link rel="stylesheet" type="text/css" href="files/mstyle.css" />
    </head>
    <body>
    <div id="main">
        <img src="files/images/header.png" alt="MENTORNET" border="0" id="header" />
 
        <table border="0" id="quick">
            <tr>
                <td><p><a href="index.html">Home</a></p></td>
                <td><p><a href="contact.html">Contact Us</a></p></td>
                <td><p><a href="calendar.html">Calendar</a></p></td>
                <td><p><a href="comments.php">Comments</a></p></td>
            </tr>
        </table>
 
        <table border="0" id="tabs">
            <tr>
                <td><p><a href="etd.html">ETD</a></p></td>
                <td><p><a href="services.html">Training Services</a></p></td>
                <td><p><a href="conference.html">Conference Facilities</a></p></td>
                <td><p><a href="community.html">Community</a></p></td>
                <td><p><a href="bee.html">BEE</a></p></td>
                <td><p class="on"><a href="registerCourse.html">Register</a></p></td>
            </tr>
        </table>
 
        <img src="files/images/topFin.png" alt="" border="0" id="top" />
        
        <div id="body">
            
            
            <center>
            <br  /><br  />
            
            <h1>Registration of Courses</h1>
            
            <div id="content">
                
                <h2>Register the courses you are interested in here</h2>
                
                <h5>Please fill in the form to register for our courses. The fields 
                marked with a red asterix are required</h5>
                
                <form name="Register Course" action="handle_form.php" method="post" enctype="multipart/form-data">
                <table border="0" class="mtable">
                    
                    <tr>
                        <td>Title:</td>
                        <td class="left1"><select name="title">
                                            <option>Mr.</option>
                                            <option>Mrs.</option>
                                            <option>Ms.</option>
                                            <option>Dr.</option>
                                            <option>Prof.</option>
                                            <option>Other</option>
                                        </select></td>
                    </tr>
                    <tr>
                        <td>Name:</td>
                        <td class="left">&nbsp;&nbsp;<input type="text" name="name" size="30"><a style="color:#ff0000">*</a></td>
                    </tr>
                    <tr>
                        <td>Surname:</td>
                        <td class="left">&nbsp;&nbsp;<input type="text" name="surname" size="30"><a style="color:#ff0000">*</a></td>
                    </tr>
                    <tr>
                        <td>ID/Passport Number:</td>
                        <td class="left">&nbsp;&nbsp;<input type="text" name="id" size="12"><a style="color:#ff0000">*</a></td>
                    </tr>
                    <tr>
                        <td>Postal Address:</td>
                        <td class="left">&nbsp;&nbsp;<textarea rows="7" cols="30" name="postal"></textarea></td>
                    </tr>
                    <tr>
                        <td>Individual or Group (choose one):</td>
                        <td class="left">&nbsp;&nbsp;<input type="radio" name="choose" value="individual"><a style="color:#ff0000">*</a><a>Individual</a>
                        <input type="radio" name="choose" value="group"><a style="color:#ff0000">*</a><a>Group</a></td>
                    </tr>
                    <tr>
                        <td>If you chose to register as a Group, how many students will be attending?</td>
                        <td class="left1"><select>
                                            <option>2</option>
                                            <option>3</option>
                                            <option>4</option>
                                            <option>5</option>
                                            <option>6</option>
                                            <option>7</option>
                                            <option>8</option>
                                            <option>9</option>
                                            <option>10</option>
                                            <option>11</option>
                                            <option>12</option>
                                            <option>13</option>
                                            <option>14</option>
                                            <option>15</option>
                                            <option>16</option>
                                            <option>17</option>
                                            <option>18</option>
                                            <option>19</option>
                                            <option>20</option>
                                            <option>21</option>
                                            <option>22</option>
                                            <option>23</option>
                                            <option>24</option>
                                            <option>25</option>
                                            <option>More than 25</option>
                                            </select><name="numberS"><a style="color:#ff0000">*</a></td>
                    </tr>   
                    <tr>
                        <td>Organisation:</td>
                        <td class="left">&nbsp;&nbsp;<input type="text"  name="organisation" size="30"></td>
                    </tr>
                    <tr>
                        <td>Contact Number 1:</td>
                        <td class="left">&nbsp;&nbsp;<input type="text" name="contact1" size="10"><a style="color:#ff0000">*</a></td>
                    </tr>
                    <tr>
                        <td>Contact Number 2:</td>
                        <td class="left">&nbsp;&nbsp;<input type="text" name="contact2" size="10"></td>
                    </tr>
                    <tr>
                        <td>Email:</td>
                        <td class="left">&nbsp;&nbsp;<input type="text" name="email" size="30"><a style="color:#ff0000">*</a></td>
                    </tr>
                    <tr>
                        <td>Unit Standard Numbers:</td>
                        <td class="left">&nbsp;&nbsp;<textarea rows="7" cols="30" name="us"></textarea><a style="color:#ff0000">*</a></td>
                    </tr>               
                    <tr>
                        <td align="center"><input type="submit" value="Submit Registration" />
                        <input type="reset" value="Reset" /></td>
                    </tr>
                </table>
                
                <br />  
                
                
            
            <br /><br />
            </div>
            </center>
            <br  />
            
        </div>
        
        <img src="files/images/bottomFin.png" alt="" border="0" id="bottom" />
        
        <br />
        <center>
        <img src="/cgi-sys/Count.cgi?df=mentorne.dat|display=Counter|ft=2|md=6|frgb=40;120;80|dd=B">
        </center>
    </div>
    </body>
</html>
and then my success page is just html saying succes.
User avatar
ghurtado
Forum Contributor
Posts: 334
Joined: Wed Jul 23, 2008 12:19 pm

Re: Is the problem with hosting server or me?

Post by ghurtado »

Instead of redirecting in case of failure, try to show the error message that Swift encounters.
hanzi
Forum Newbie
Posts: 3
Joined: Mon Aug 18, 2008 7:38 am

Re: Is the problem with hosting server or me?

Post by hanzi »

okay cool, so how do I do that?
hanzi
Forum Newbie
Posts: 3
Joined: Mon Aug 18, 2008 7:38 am

Re: Is the problem with hosting server or me?

Post by hanzi »

anybody? I have to get this working asap but I don't know how. :banghead:
Post Reply