0
    function email($reqNo){
        //Database Configurations
        $host = "some.url";
        $username = "someuser";
        $pass = "xxxxxx";
        $db = "mydatabase_db";

        //Customer Configurations
        $cName = null;
        $cEmail = null;

        $DBConnect = @mysqli_connect($host, $username, $pass, $db) or die
        ("<p>Unable to connect to the database server.</p>". "<p>Error code ". mysqli_connect_errno().": ". mysqli_connect_error()). "</p>";

        $SQLString = "SELECT name, email FROM Customer WHERE cust_no = '" .getInfor("cno"). "'";
        $queryResult = @mysqli_query($DBConnect, $SQLString) or die
        ("<p>Unable to query the $TableName table.</p>"."<p>Error code ". mysqli_errno($DBConnect). ": ".mysqli_error($DBConnect)). "</p>";

        $row = mysqli_fetch_row($queryResult);

        while ($row) {
            $cName = $row[0];
            $cEmail = $row[1];
            $row = mysqli_fetch_row($queryResult);
        }

        mysqli_close($DBConnect);

        // Email Information Configurations
        $pdate = date("Y-m-d", strtotime(getInfor("p_date")));
        $ptime = date("H:i:s", strtotime(getInfor("p_time")));
        $to = $cEmail;
        $header = "From: admin@shiponline.com";
        $subject = "Shipping Request with ShipOnline";
        $message = "Dear $cName, Thank you for using ShipOnline! Your request number is $reqNo. "
                    ."The cost is " .calCost(). ". We will pick-up the item at $ptime on $pdate.";

        // Send Email
        mail($to, $subject, $message, $header);     
    }

This function is execute without any errors display.
But I am just couldn't get the mail from it.
Am I missing something on that?

P/S: The email of the receipent is myself.

Edited by Reverend Jim: Removed password

4
Contributors
17
Replies
68
Views
2 Months
Discussion Span
Last Post by gahhon
Featured Replies
  • You can't send e-mail from localhost without an smtp server running and a lot of (free) hosts have it disabled by default. The free ones usually require a tiny payment to enable email as a way to discourage spammers. Also, change your mariadb user name and password because you seem … Read More

  • > I don't any edit button on the post? If you could edit it would still be a risk. Google will have indexed the page by now so people can still view the cached versions. If it's a database that's runned by the university maybe contact someone from tech support … Read More

  • 2
    diafol 3,547   2 Months Ago

    You may be in luck that you may need to be on the server (as localhost) to make a connection. I believe you are. But others on the server could use your credentials to cause mayhem. Read More

  • 1
    diafol 3,547   2 Months Ago

    If you set up your own local stack - some bundles come with Mercury mail or similar, an email server that you can use to test. You can copy your remote db to your pc for testing. When I don.t specifically allow my IP access to my remote dbs, I … Read More

3

You can't send e-mail from localhost without an smtp server running and a lot of (free) hosts have it disabled by default. The free ones usually require a tiny payment to enable email as a way to discourage spammers.

Also, change your mariadb user name and password because you seem to have posted them:

$username = "s100042374";
$pass = "081292";
1

I don't any edit button on the post?

If you could edit it would still be a risk. Google will have indexed the page by now so people can still view the cached versions. If it's a database that's runned by the university maybe contact someone from tech support and see if they can change the password for you.

2

You may be in luck that you may need to be on the server (as localhost) to make a connection. I believe you are. But others on the server could use your credentials to cause mayhem.

0

I had tried to do alot of changes of it. Like update the $header, but it is still not work.
At last, I put if-else statement on the mail() functions and it is return false. Which means there is something wrong at mail() function and caused it return false.
Any advise?

0

Are you sure you are allowed to send mail from your server? Localhost can't on its own and most hosts block it. Maybe look into using an smtp server with PHP to send mails, for instance, with your google account.

PS, to the mod that edited OP's snippet: feel free to censor my post as well.

0

Traevel,

I am not sure whether I am allowed to send the mail from my server or not.
However, I am away from University, therefore I will connect to my University network by using Cisco AnyConnect and WinSCP to submit my work.

As I had look through the link you provided. It is similar to others discussion, which have download some package to enable the mail function work properly.
If there anyway to enable mail function work properly in php without download any packages?
Because this work will be test by my tutor, but not on my laptop.

Edited by gahhon

0

Well even the official PHP mail page makes references to the PEAR package and encourages its use. Down in the comments there are some people who tinker with the php.ini and sendmail.ini to get it to use google smtp, but your tutor wouldn't have those either. If possible I would try to send him/her the entire package of your code, including any libraries.

0

So if I am successful to send the mail by downloading the PEAR package, then I must submit the work together with the package to my tutor in order to let my tutor test out the effect?
I am noted, will right away and apply this approach.

0

Yes, but, from that page:

All it takes is the right configuration (to send mail using a local or a remote server)

So make sure that you include those configurations when you notify your tutor. Or it won't work on their machine.

You don't need PEAR (it only makes things easier and has more options) but you do need to specify an SMTP if you're running your page from localhost. If you're running it on an online host it will depend on their settings.

0

I don't think I am running my page from localhost.
Because when my page wasn't start at localhost:......../contactus.php
Instead, my page was run at a University Mercury server http://mercury.swin.edu.au/....../contactus.php

0

You usually access db server and email server as localhost under php - this does not mean you can access them from "your own" localhost (own PC).

0

So what should I do in order to get my mail() function?

Everytime I test my project, I have to connect to my university network in order to test the pages. Otherwise, it will be error, with my own network.

1

If you set up your own local stack - some bundles come with Mercury mail or similar, an email server that you can use to test. You can copy your remote db to your pc for testing. When I don.t specifically allow my IP access to my remote dbs, I just run a copy of the db and have a two config files. One for remote and one for local.

0

However, I am able to send the email to corressponding email address without any downloading any packages.
This is because the From: admin@admin.com is invalid email address. If I am change it to my student mail address and it works fine!
Would be the matter of university mercury server thingy.

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.