Another solution i've been searching for days now is for sending mail to actually existing accounts, but haven't quite found it yet. I have this functionality in my code where i can search and select professors individually for setting question papers. The search and select pages are working fine, so is the page where i assign them login credentials for setting papers. Now, since i(as admin) am assigning them the login credentials, i need to communicate that information to the selected professors. For this, i figured i'd mail them. I've set up a valid gmail account from where i want this mail to be sent. But my sendmailselected.php file is not working and is erroneous. I will take care to prevent sql injection so that is no issue. Also note that i have made changes in my php.ini file as required, and also have sendmail.zip and sendmail-SSL.zip folders extracted in the bin folder of wamp. Can you please point out errors and help me out. Here's the code:

<?php
include('connectionfile.php');
session_start();
if (!isset($_SESSION["useradmin"])) { 
    header("Location: index.html");
}


echo "<br><p>";

$prof_id = $_POST['prof_id'];
$temp_id = $_POST['temp_id'];
$temp_usname=$_POST['temp_uname'];
$temp_pswd = $_POST['temp_pwd'];
$temp_status = $_POST['status_paper'];
$sname= $_POST['sname'];
$my= $_POST['my'];



$insert_temp = "INSERT INTO temporary (prof_id, temp_id, temp_uname, temp_pwd, subject_name, monthandyear, status) VALUES ( '".$prof_id."', '".$temp_id."', '".$temp_usname."', '".$temp_pswd."', '".$sname."', '".$my."', '".$temp_status."')";

mysql_query($insert_temp) OR die (mysql_error());


$profmail= "select prof_email_id from professor where prof_id= $prof_id ";

$gotid = mysql_query($profmail) OR die (mysql_error());

$message= "You have been selected for question paper setting for the examination to be held in $my for the subject $subj and your temporary login credentials are as follows: <br> Temporary Username: $temp_usname <br> Temporary ID: $temp_id <br> Temporary Password: $temp_pswd . Please see to it that you sign in and submit the question paper before 10 days. After this period, your temporary account will expire."



$messagelong = wordwrap($message, 3, "\n", true);
$messagelong = wordwrap($message);


ini_set(sendmail_from, ' my gmail account id here ');   

mail($profmail, "Selected for paper setting", $message);
ini_restore("sendmail_from"); 


echo("<p><br> Entry for $temp_id successfully inserted and mail sent.");

mysql_close($id_link);


?>

There is this link i referred to for changes to be made in the php.ini and sendmail.php files. If you need to see that, tell me, i'll post the link. Thanks! :)

my sendmailselected.php file is not working and is erroneous

What's not working, and what's erronous?

I get this when this file is executed:
Notice: Use of undefined constant sendmail_from - assumed 'sendmail_from' in sendmailselected.php on line 123.
Here those lines are:

ini_set(sendmail_from, ' my gmail account id here ');   
$sent = mail($profmailsend, "Selected for paper setting", $newtext, "From: <Uni Admin>");
ini_restore("sendmail_from");     

Hence the mail is not getting sent.

Now only this file doesn't work. Please help me solve my problem asap. Thanks!

Your sendmail_from should be in quotes.

tried doing that, still shows me a parse error on the same lines of code.

Member Avatar for LastMitch

Notice: Use of undefined constant sendmail_from - assumed 'sendmail_from' in sendmailselected.php on line 123.

Which line of code?

Is it this one:

ini_set(sendmail_from, 'my gmail account id here'); 

tried doing that, still shows me a parse error on the same lines of code.

From this:

ini_set(sendmail_from, 'your email address'); 

to this:

ini_set('sendmail_from', 'your email address'); 

Did you get the same error?

I notice the code you provided above on line 38 to line 41 doesn't have qoutes either put it too:

ini_set('sendmail_from', ' my gmail account id here ');
mail($profmail, "Selected for paper setting", $message);
ini_restore("sendmail_from");

Okay, now no errors. The mail function seems to be working fine. Tested it using the following lines of code:

if($sent) 
{print "<br>Your mail was sent successfully"; }
else 
{print "<br>We encountered an error sending your mail"; }

and when i execute it shows me 'Your mail was sent successfully'. But when i check my gmail acc to which the mail was sent to, i have not received any mail, neither in inbox nor in junk folders. Plus, i checked the admin acc too, and it shows 'no sent mails'. Is there anything else i left out in my coding? I even put my wamp server online before sending the mail... please assist me!

Member Avatar for LastMitch

But when i check my gmail acc to which the mail was sent to, i have not received any mail, neither in inbox nor in junk folders.

I am assuming in your database your email address is valid?

wamp server online before sending the mail

So you are running this from you development machine? Do you have a mail server installed?

Member Avatar for LastMitch

yes it is...

Like what pritaeas mention did you installed a mail server?

I think I forgot to ask that question in the beginning.

Member Avatar for LastMitch

Yes i guess

Do you have something like that or you don't?

If you don't take a look at these articles (instructions) on how to setup SMTP:

http://wiki.qnap.com/wiki/How_to_configure_the_SMTP_server_with_your_G-Mail_account

http://www.xtreemhost.com/2010/04/11/how-to-send-e-mails-via-smtp-with-phpmailer-and-gmail/

Take a look at these code snippets which has a SMTP files in it (both of these are tutorials about sending emails with SMTP):

http://www.web-development-blog.com/archives/send-e-mail-messages-via-smtp-with-phpmailer-and-gmail/

http://www.9lessons.info/2009/10/send-mail-using-smtp-and-php.html

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.