Forum Moderators: coopster

Message Too Old, No Replies

using forms: sendmail enabled, smtp not enabled

         

jpolsonb

3:30 am on Jun 15, 2009 (gmt 0)

10+ Year Member



If my server has php sendmail enabled but not smtp can i still send emails with a contact form on my flash site? I have posted my scripts but i think they are fine, i just don't know anything about servers and cant find any info pertaining to my particular situation (ie. flash embedded in xhtml, using contact form with sendmail enabled, smtp not enabled)

The contact form is in flash movie embedded in index.html. The flash file and php file are together in a subdirectory. Would this affect its function?

The server is running apache 2... and php 5...

Any advice would be appreciated.

This is the php script called flashEmailer.php:
----------------------------------------------------------
$recipients = "myemail@example.com";
$subject = "The Message";

// Grab the key from Flash to ensure security
$sendKey = $_POST['key'];

// Only allow the page to send if Flash is the requester
if($sendKey == "email") {
// The following three variables are gathered from Flash
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];

// Grab todays date
$date = date("F j, Y", time());

// This block is the actual message that is sent in the email
$email_info .= "Below is the visitors contact info and message.\n\n";
$email_info .= "Visitor's Info:\n";
$email_info .= "-----------------------------------------\n";
$email_info .= "Name: " . $name . "\n";
$email_info .= "Email: " . $email . "\n";
$email_info .= "Date Sent: " . $date . "\n\n";
$email_info .= "Message\n";
$email_info .= "-----------------------------------------\n";
$email_info .= "" . $message . "\n";

$mailheaders = "From: email@example.com <> \n";
$mailheaders .= "Reply-To: " . $email . "\n\n";

if(mail($recipients, $subject, $email_info, $mailheaders)) {
// Print a success for Flash to know the email is being sent
print "&success=true";
}
}

?>

------------------------------------------------------------

This is the actionscript for the contact form.
-------------------------------------------------------------

var contact_php_file = "flashEmailer.php";

send_btn.onRelease = function() {
checkForm();
}

function validateEmail(address) {
// Check address length
if(address.length >= 7) {
// Check for an @ sign
if(address.indexOf("@") > 0) {
// Check for at least 2 characters following the @
if((address.indexOf("@") + 2)<address.lastIndexOf(".")) {
// Check for a domain name of at least 2 characters
if (address.lastIndexOf(".") < (address.length - 2)) {
// If all the above tests pass, the email address is in valid format
return true;
}
}
}
}
// Called if the email fails
trace("The entered email address is invalid.");
return false;
}

function checkForm() {
n = form.name_txt.text;
e = form.email_txt.text;
m = form.msg_txt.text;
if(m != "" && e != "" && validateEmail(e)) {
sendEmail(n, e, m);
} else {
trace("All Required Fields Not Filled In!");
}
}

function sendEmail(n, e, m) {
session = "?nocache=" + random(999999);
contact_lv = new LoadVars();
contact_lv.name = n;
contact_lv.email = e;
contact_lv.message = m;
contact_lv.key = "email";
trace(n + " - " + e + " - " + m);
contact_lv.sendAndLoad(contact_php_file + session, contact_lv, "POST");
contact_lv.onLoad = function(success) {
if(!success) {
return trace("Error calling PHP File!");
} else {
return trace("Email Sent!");
}
}
}

stop();

[edited by: dreamcatcher at 7:00 am (utc) on June 15, 2009]
[edit reason] Removed specifics [/edit]

jatar_k

11:52 am on Jun 15, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



what happens when you try to send the email?

jpolsonb

2:02 pm on Jun 15, 2009 (gmt 0)

10+ Year Member



I don't recieve it in my gmail account.

Not sure how to do any kind of error checking in php?

jatar_k

2:12 pm on Jun 15, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



this part will check to see if the mail function got a true response

if(mail($recipients, $subject, $email_info, $mailheaders)) {
// Print a success for Flash to know the email is being sent
print "&success=true";
}

that just means that your message was successfully added to the mail queue, in this case to sendmail's mail queue

you could look at the maillog in sendmail, mine happens to be located at /var/log/maillog that could show you more about what happened to the message.

The odds are you just aren't getting it, check your spam folder first.

Then I would make sure you have an email address you control in the headers

$mailheaders = "From: email@example.com <> \n";
$mailheaders .= "Reply-To: " . $email . "\n\n";

and add a couple that help

$myemail = 'email@example.com';
$mailheaders = "From: $myemail <$myemail>\n";
$mailheaders .= "Return-Path: $myemail\n";
$mailheaders .= "Reply-To: $myemail\n";

try with that chunk and see what happens, if you set the $myemail var to an account you control you may get a bounce message that might help as well.

jpolsonb

2:45 am on Jun 16, 2009 (gmt 0)

10+ Year Member



Hey thanks for the reply will try all your suggestions.

jpolsonb

7:01 am on Jun 16, 2009 (gmt 0)

10+ Year Member



I am still having no luck. When I click submit it says looking up/waiting for sql4.net/i fastnet.com or other random addresses in the status bar at the bottom (firefox.

I have set up apache and php 5 as local host.

How can I check if the mail is being sent by using local host.

Its actually quite embarassing but I found an article that seemed to have the solution, but involved setting up apache and php 5. Anyway it took me ages and when i finally got it working I realised I had cleared the cache and cant find the article again for the life of me!

Pretty silly...

jpolsonb

8:18 am on Jun 16, 2009 (gmt 0)

10+ Year Member



just to clarify, it is possible to send mail with a contact form without smtp enabled?

mvaz

10:40 am on Jun 16, 2009 (gmt 0)

10+ Year Member



In your php.ini file, change the smtp to what ever is yours and you should be on your way to send emails using your local host / smtp.

jatar_k

12:56 pm on Jun 16, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I am a bit confused, we have established that you have php/apache

is the script running on a server or your local machine?
what's the OS?
do you have sendmail installed?
what is the action of your form set to? a script on the same machine?

jpolsonb

1:56 pm on Jun 16, 2009 (gmt 0)

10+ Year Member



Im running vista have installed apache2.2 and php5 om my computer which is running windows vista. Im trying to send an email from the form in the flash movie embedded in index.html to my personal email account. The server that the site is hosted on has sendmail() enabled but not smtp. The host has the same versions of apache and php. I have tested the variables for the input boxes in flash and they are fine.

I am also trying to acheive the same thing from localhost as a means of testing but I cant work it out.

jatar_k

2:11 pm on Jun 16, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



well unless your server is running windows, which i doubt if it has sendmail, then your local configuration or trouble shooting will be irrelevant to the server.

did you test the things I mentioned on your server?

you can use sendmail to send mail, you don't need "smtp installed" per se, so leave that for now

don't worry about your local setup as you need to diagnose what is happening on the server.

so step 1

was the mail function successful?

how to test

you currently have this
if(mail($recipients, $subject, $email_info, $mailheaders)) {
// Print a success for Flash to know the email is being sent
print "&success=true";
}

which seems to print "&success=true" when the mail function is successful, not my approach but

does this get output when you submit your form?

I might change the above if to output something for false too

if(mail($recipients, $subject, $email_info, $mailheaders)) {
// Print a success for Flash to know the email is being sent
print "&success=true";
} else {
print "&success=false";
}

jpolsonb

2:57 pm on Jun 16, 2009 (gmt 0)

10+ Year Member



This is the result of testing the mail function:

bob - notmyemail@hotmail.com - this is a message
Error calling PHP File!
Error opening URL "file:///D¦/websites/SouthBank%20Web%20Design/css/flash/flashEmailer.php?nocache=472168"

I have done everything that you have suggested so far.

jatar_k

3:12 pm on Jun 16, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



is that running on the server?

the url can't be like that, that would be a local filepath

where do you set the action for the form? I don't know actionscript (nor do i care to ;)) but it looks like the first issue is finding the script, it presently seems to be looking for a local filepath

jpolsonb

1:08 am on Jun 17, 2009 (gmt 0)

10+ Year Member



That is when i tested it on the local machine.

When i test it on the server i dont know how to do any form of error checking.

the action for the form is :

var contact_php_file = "flashEmailer.php";

and is called
when all the criteria are met for filling in the form:

contact_lv.sendAndLoad(contact_php_file + session, contact_lv, "POST");

the file flashEmailer.php is in the same location as the flash movie.

-----------------------------------------------------------

In short can you give me advice on how to check the mail function on the server. I don't have access to or don't know how to find the maillog file. Im sure my actionscript is not the problem.

How do i display the result of the error checking that i have put in my flash files when the site is online?

jpolsonb

1:22 am on Jun 17, 2009 (gmt 0)

10+ Year Member



Here are some of the php settings of my host from phpinfo().

sendmail_from: no value
sendmail_path: /usr/sbin/sendmail -t -i
SMTP: localhost
smtp: _port25
REQUEST_METHOD: GET

SMTP server: Available on premium only - Upgrade
PHP Sendmail: Enabled

jpolsonb

6:21 am on Jun 17, 2009 (gmt 0)

10+ Year Member



ok i have uploaded this as testMail.php...

<?
mail("example@gmail.com","test","Ok, it works");
?>

..and opened it in my browser. I receive no email in my inbox so I can only conclude that the server I am hosted by will not allow me to send mail.

I cannot understand why.

jpolsonb

7:04 am on Jun 17, 2009 (gmt 0)

10+ Year Member



Im changing hosts as of now.

jatar_k

3:14 pm on Jun 17, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



the first check would be this

<?
$diditgo = mail("example@gmail.com","test","Ok, it works");
if ($diditgo) echo "the mail function returned true so it worked.";
else echo "the mail function returned false, very sad.";
?>