LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-26-2016, 07:49 PM   #1
Pedroski
Senior Member
 
Registered: Jan 2002
Location: Nanjing, China
Distribution: Ubuntu 20.04
Posts: 1,957

Rep: Reputation: 70
PHP5 and a contact form


At home, on my little laptop, I made a simple webpage and I'm trying a contact form.

When I click on submit, instead of submitting, I get a window asking me what I want to open send_mail.php with. It suggests Geany.

I have put my email in send_mail.php

Quote:
$webmaster_email = "mymail@foxmail.com"
I have installed:

Quote:
pedro@pedro-schule:~$ php --version
PHP 5.5.9-1ubuntu4.17 (cli) (built: May 19 2016 19:05:57)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies
pedro@pedro-schule:~$
What do I need to do to make the php script do its job??

Last edited by Pedroski; 06-26-2016 at 08:08 PM.
 
Old 06-26-2016, 09:04 PM   #2
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,824

Rep: Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615
Configure whatever Web server you have running to handle serving PHP correctly.
 
Old 06-26-2016, 09:34 PM   #3
Pedroski
Senior Member
 
Registered: Jan 2002
Location: Nanjing, China
Distribution: Ubuntu 20.04
Posts: 1,957

Original Poster
Rep: Reputation: 70
Ok, thanks. I have apache2 installed.

Which conf file needs what addition?

I am trying to run the webpage from /home/pedro/mywebpage This is my /etc/apache/mods-available/php5.conf I commented out the last bit. I thought it would make php work there.

Quote:
<FilesMatch ".+\.ph(p[345]?|t|tml)$">
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch ".+\.phps$">
SetHandler application/x-httpd-php-source
# Deny access to raw php sources by default
# To re-enable it's recommended to enable access to the files
# only in specific virtual host or directory
Order Deny,Allow
Deny from all
</FilesMatch>
# Deny access to files without filename (e.g. '.php')
<FilesMatch "^\.ph(p[345]?|t|tml|ps)$">
Order Deny,Allow
Deny from all
</FilesMatch>

# Running PHP scripts in user directories is disabled by default
#
# To re-enable PHP in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.

#the following commented out by me
#<IfModule mod_userdir.c>
# <Directory /home/*/public_html>
# php_admin_flag engine Off
# </Directory>
#</IfModule>

Last edited by Pedroski; 06-26-2016 at 10:14 PM.
 
Old 06-27-2016, 06:47 AM   #4
Pedroski
Senior Member
 
Registered: Jan 2002
Location: Nanjing, China
Distribution: Ubuntu 20.04
Posts: 1,957

Original Poster
Rep: Reputation: 70
I read some more and changed /etc/php5/php.ini

I inserted this

Quote:
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
;changed by me
sendmail_path = /usr/sbin/sendmail -t -i
;sendmail_path =
But I still don't get any mail!
 
Old 06-27-2016, 08:10 AM   #5
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 20 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924
Can you please check that you've carried out all the necessary install steps here:

https://www.digitalocean.com/communi...tack-on-ubuntu
 
Old 06-27-2016, 07:27 PM   #6
Pedroski
Senior Member
 
Registered: Jan 2002
Location: Nanjing, China
Distribution: Ubuntu 20.04
Posts: 1,957

Original Poster
Rep: Reputation: 70
[side note: I got a message that it would be impossible to send email from my home computer to the public internet. If that's true I can stop wasting my time.]

Thanks for that.

I got apache2 working. I got the default page. So I moved my personal webpage to /var/www/html and it works, I see it when I enter localhost in Firefox.

I got php working. I get the php info page.

My problem seems to lie in sendmail. sendmail was present in /usr/sbin but it was a dummy, almost empty file.

So I installed sendmail, which seems quite complex, a lot of files which may or may not need tweaking.

I ran sendmailconfig and that's probably where the devil lies: too many settings, which are right for me??

I am in China, so I use mail.qq.com

The domain is qq.com, POP3 is pop.qq.com:995 smtp is smtp.qq.com ports 465 to 587

I want my webpage to send mail to my qq mail address when the user clicks submit.

php has the function mail()

My contact form page does not give me any error message, but I do not get any mail.

The trick here is, I believe, to get sendmail working. If you know a good link for that, I would be very grateful.

I don't know if php can work with postfix, which is more 'native' to Ubuntu.

This link is good, but I can't get sendmail to work. Is it really that difficult??

http://stackoverflow.com/questions/1...mail-on-ubuntu

Maybe, when I get around to publishing my web page, it will work on the server. I would still like to make it work on my laptop, just for the experience.

I think I need a working smtp server to send the mails.

This does not work at the moment and I don't know why. I changed the email to my email.

Quote:
$ echo "My test email being sent from sendmail" | /usr/sbin/sendmail myemail@domain.com
This is the last bit of /var/log/mail.log from yesterday

Quote:
Jun 27 21:49:23 pedro-schule sendmail[3670]: alias database /etc/mail/aliases rebuilt by pedro
Jun 27 21:49:23 pedro-schule sendmail[3670]: NOQUEUE: SYSERR(root): /etc/mail/aliases: line 1: missing colon
Jun 27 21:49:23 pedro-schule sendmail[3670]: /etc/mail/aliases: 0 aliases, longest 0 bytes, 0 bytes total
Jun 27 21:49:37 pedro-schule sm-mta[1445]: restarting /usr/sbin/sendmail-mta due to signal
Jun 27 21:49:37 pedro-schule sm-mta[3714]: starting daemon (8.14.4): SMTP+queueing@00:10:00
Jun 27 21:51:34 pedro-schule sendmail[3891]: u5RDpYPs003891: from=www-data, size=99, class=0, nrcpts=1, msgid=<201606271351.u5RDpYPs003891@pedro-schule.net>, relay=www-data@localhost
Jun 27 21:51:34 pedro-schule sm-mta[3892]: STARTTLS=server, relay=localhost [127.0.0.1], version=TLSv1/SSLv3, verify=NOT, cipher=DHE-RSA-AES256-GCM-SHA384, bits=256/256
Jun 27 21:51:34 pedro-schule sendmail[3891]: STARTTLS=client, relay=[127.0.0.1], version=TLSv1/SSLv3, verify=FAIL, cipher=DHE-RSA-AES256-GCM-SHA384, bits=256/256
Jun 27 21:51:34 pedro-schule sm-mta[3892]: u5RDpYmo003892: from=<www-data@pedro-schule.net>, size=328, class=0, nrcpts=1, msgid=<201606271351.u5RDpYPs003891@pedro-schule.net>, proto=ESMTP, daemon=MTA-v4, relay=localhost [127.0.0.1]
Jun 27 21:51:34 pedro-schule sendmail[3891]: u5RDpYPs003891: to=rapidresults@foxmail.com, ctladdr=www-data (33/33), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30099, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (u5RDpYmo003892 Message accepted for delivery)
Jun 27 21:51:35 pedro-schule sm-mta[3894]: STARTTLS=client, relay=mx2.qq.com., version=TLSv1/SSLv3, verify=OK, cipher=RC4-SHA, bits=128/128
Jun 27 21:51:40 pedro-schule sm-mta[3894]: u5RDpYmo003892: to=<rapidresults@foxmail.com>, ctladdr=<www-data@pedro-schule.net> (33/33), delay=00:00:06, xdelay=00:00:06, mailer=esmtp, pri=120328, relay=mx2.qq.com. [120.198.201.148], dsn=5.0.0, stat=Service unavailable
Jun 27 21:51:40 pedro-schule sm-mta[3894]: u5RDpYmo003892: u5RDpemn003894: DSN: Service unavailable
Jun 27 21:51:40 pedro-schule sm-mta[3894]: u5RDpemn003894: to=<www-data@pedro-schule.net>, delay=00:00:00, xdelay=00:00:00, mailer=local, pri=30000, dsn=2.0.0, stat=Sent
Also, I'm not sure if the sendmail path in /etc/php5/apache2/php.ini should have "" or not:

This:

Quote:
sendmail_path = "/usr/sbin/sendmail -t -i -f fromMe@blah.com"
or this

Quote:
sendmail_path = /usr/sbin/sendmail -t -i -f fromMe@blah.com

Last edited by Pedroski; 06-27-2016 at 08:41 PM.
 
Old 06-27-2016, 07:54 PM   #7
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 20 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924
Googling ubuntu sending mail apache produces results such as the following:

http://askubuntu.com/questions/47609...-php-send-mail

Have a read through the various results, which suggest both sendmail and postfix solutions.

My advice would be to keep things simple and test whichever method you choose through the command line before testing it through php.

Sorry I can't give you better help than that as I don't send mail through my local server. Perhaps someone else will be able to offer you better help.

Please let us know how you get on.
 
Old 06-27-2016, 10:32 PM   #8
Pedroski
Senior Member
 
Registered: Jan 2002
Location: Nanjing, China
Distribution: Ubuntu 20.04
Posts: 1,957

Original Poster
Rep: Reputation: 70
Well, I got the tip to use ssmtp, they said sendmail or postfix are both overkills for my purpose, which is just sending an email to me.

I installed ssmtp which uninstalls sendmail, puts a symlink in /usr/sbin

I am getting closer.

This is the last bit of my /var/log/mail this morning:

Quote:
Jun 28 10:00:02 pedro-schule sSMTP[2182]: Server didn't like our AUTH LOGIN (530 Must issue a STARTTLS command first.)
Jun 28 10:06:14 pedro-schule sSMTP[2841]: Server didn't like our AUTH LOGIN (530 Must issue a STARTTLS command first.)
Jun 28 10:09:02 pedro-schule sSMTP[2916]: Server didn't like our AUTH LOGIN (530 Must issue a STARTTLS command first.)
Jun 28 10:19:54 pedro-schule sSMTP[3093]: Creating SSL connection to host
Jun 28 10:19:55 pedro-schule sSMTP[3093]: SSL connection using RSA_ARCFOUR_SHA1
Jun 28 10:19:55 pedro-schule sSMTP[3093]: Authorization failed (535 Error: \C7\EBʹ\D3\C3\CA\DAȨ\C2\EB\B5\C7\A1\A3\CF\EA\C7\E9\C7뿴: http://service.mail.qq.com/cgi-bin/h...28&&no=1001256)
Jun 28 10:20:01 pedro-schule sSMTP[3114]: Creating SSL connection to host
Jun 28 10:20:01 pedro-schule sSMTP[3114]: SSL connection using RSA_ARCFOUR_SHA1
Jun 28 10:20:02 pedro-schule sSMTP[3114]: Authorization failed (535 Error: \C7\EBʹ\D3\C3\CA\DAȨ\C2\EB\B5\C7\A1\A3\CF\EA\C7\E9\C7뿴: http://service.mail.qq.com/cgi-bin/h...28&&no=1001256)
I set ssmtp.conf to:

UseSTARTTLS=yes
UseTLS=yes

AuthUser=my_foxmail_account_name@foxmail.com
AuthPass=my_password

qq.com doesn't like this kind of 'satellite' log in probably.

Any more tips??
 
Old 06-28-2016, 08:05 AM   #9
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 20 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924
Ok, I've just got ssmtp working on my test rig (Mint 17.3 64-bit Xfce). Here is how I did it. Replace gedit with your editor of choice and items in italics with your particular details. I've set this up with gmail - I would advise you to do that in the first place and then try with another email provider after you get it working.

Info taken from: http://www.havetheknowhow.com/Config...all-ssmtp.html

Code:
sudo apt-get update
sudo apt-get install ssmtp
(installs ssmtp 2.64-7)

Code:
sudo gedit /etc/ssmtp/ssmtp.conf
and change to the following:

Code:
# Config file for sSMTP sendmail
#
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
root=username@gmail.com

# The place where the mail goes. The actual machine name is required no 
# MX records are consulted. Commonly mailhosts are named mail.domain.com
mailhub=smtp.gmail.com:587

AuthUser=username@gmail.com
AuthPass=password
UseTLS=YES
UseSTARTTLS=YES

# Where will the mail seem to come from?
rewriteDomain=gmail.com

# The full hostname
hostname=smtp.gmail.com:587

# Are users allowed to set their own From: address?
# YES - Allow the user to specify their own From: address
# NO - Use the system generated From: address
FromLineOverride=YES
Then I went onto Gmail and changed the following setting:

Code:
My Account->Sign-in & security->Allow less secure apps: ON
Then back on the command line:

Code:
ssmtp destination_email_address
and entered:

Code:
To: destination_email_address
From: username@gmail.com
Subject: Testing

Hello world!
then pressed Ctrl-D.

Note that ssmtp gets the job done but has some drawbacks and caveats - see https://www.linux.com/news/ssmtp-sim...ative-sendmail.
 
Old 06-28-2016, 08:17 PM   #10
Pedroski
Senior Member
 
Registered: Jan 2002
Location: Nanjing, China
Distribution: Ubuntu 20.04
Posts: 1,957

Original Poster
Rep: Reputation: 70
Hi, Good Morning!

Thanks for your efforts on my behalf! Very grateful!

I looked through all the settings on my email settings, but I do not find anything corresponding to

Quote:
My Account->Sign-in & security->Allow less secure apps: ON
I tried setting the AuthMeth to CRAM-MD5 but then I get:

Quote:
Jun 29 08:04:58 pedro-schule sSMTP[3651]: SSL connection using RSA_ARCFOUR_SHA1
Jun 29 08:04:58 pedro-schule sSMTP[3651]: Server rejected AUTH CRAM-MD5 (502 Error: auth command not implemented)
Without that I get the same as yesterday:

Quote:
Jun 29 08:06:50 pedro-schule sSMTP[3657]: Creating SSL connection to host
Jun 29 08:06:50 pedro-schule sSMTP[3657]: SSL connection using RSA_ARCFOUR_SHA1
Jun 29 08:06:51 pedro-schule sSMTP[3657]: Authorization failed (535 Error: \C7\EBʹ\D3\C3\CA\DAȨ\C2\EB\B5\C7\A1\A3\CF\EA\C7\E9\C7뿴: http://service.mail.qq.com/cgi-bin/h...28&&no=1001256)
In a terminal I am getting the same errors showing as are written to the mail.log.

In China you have to get a license (ICP Internet Content Provider license) to open a web site. We have that now, but the ISP says they have not yet been officially informed by the authorities, so web site is not public yet. Once our webpage is open I'll try this again from the web site. If it doesn't work then, I'll ask the ISP to help.

Unless of course you have any other ideas!

Thanks again!
 
Old 06-28-2016, 08:24 PM   #11
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 20 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924
You perhaps missed the bit where I said "Then I went onto Gmail and changed the following setting:".

Code:
My Account->Sign-in & security->Allow less secure apps: ON
should be done in your Gmail account.

Are you able to have access to a Gmail account to test carry out the steps I laid out? It will no doubt work with other email providers, although not all, but I know it works with Gmail.

You shouldn't need to be playing around with other settings. Try to keep it simple.
 
Old 06-30-2016, 08:44 PM   #12
Pedroski
Senior Member
 
Registered: Jan 2002
Location: Nanjing, China
Distribution: Ubuntu 20.04
Posts: 1,957

Original Poster
Rep: Reputation: 70
Good Morning,

been away for a few days, sorry for the late reply. I did note your advice about the setting, but qqmail does not have an equivalent setting, as far as I can see.

We live in China. google is not available except using a vpn. I can't just open gmail. I have a vpn, but not everybody does, so I'd rather not use gmail. The mails sent from here may or may not arrive, depending on the mood of the government!

qq is big in China, everyone has it. foxmail.com is just an alias for qq.com

Once the site is open, I'll try this from there. We still haven't got a functioning webpage, they company still has not received official approval, although we have.
 
Old 07-09-2016, 02:21 AM   #13
Pedroski
Senior Member
 
Registered: Jan 2002
Location: Nanjing, China
Distribution: Ubuntu 20.04
Posts: 1,957

Original Poster
Rep: Reputation: 70
Hi again,

to take up this thread again: now we have our web page online, but the contact form still will not work. I wonder if you have any idea why not.

If you go to www.rapidresults.wang and then contact>send us a message you can see the contact form.

A right click and you can view the source code. If you then click on send_mail.php you will see this error:

Quote:
PHP Notice: Undefined index: email_address in D:\freehost\fa5d40d2\web\send_mail.php on line 21
PHP Notice: Undefined index: comments in D:\freehost\fa5d40d2\web\send_mail.php on line 22
Line 21 and 22 from send_mail.php are:

$email_address = $_REQUEST['email_address'] ;
$comments = $_REQUEST['comments'] ;


These variables are defined in send_us_a_message.html here, (at least that's what I thought):

Where must I define them??

Quote:
<input type="text" name="email_address" and <textarea name="comments"
this is the relevant part of send_us_a_message.html

Quote:
<form action="send_mail.php" method="post">
<table style="text-align:left; ">
<tr>
<td>Your Email Adress:</td>

<td>
<input type="text" name="email_address" value="" maxlength="100" style="width:260px; height:20px; background-color:#D0F18F;" />
</td>
</tr>
<tr>
<td>Comments:</td>
<td>
<textarea name="comments" id="comments" style="text-align:left; width:520px; height:90px; background-color:#D0F18F;">
This form is NOT working at the moment, please email us directly. Sorry for the inconvenience.
</textarea>
</td>
 
Old 07-09-2016, 12:49 PM   #14
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 20 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924
You may have other things wrong, but at a minimum:

method="post"

therefore you should be using $_POST[], not $_REQUEST[].
 
Old 08-16-2016, 11:56 PM   #15
Pedroski
Senior Member
 
Registered: Jan 2002
Location: Nanjing, China
Distribution: Ubuntu 20.04
Posts: 1,957

Original Poster
Rep: Reputation: 70
As an afterthought:

It still won't work. The web hosting people are useless, they just say we don't know anything about web pages, but I think I may know why it will not work: The server is a Windows server and Windows does not/may not use PHP, it uses asp.net, whatever that is.

I saw a tutorial on the net about how to set up a contact form using asp. Haven't tried it yet, but I will look into it.

Can Windows use PHP?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with PHP contact form not working in IE Graz73 Programming 1 10-17-2014 01:53 PM
Wordpress and contact form 7 plugin harry_ord General 0 06-21-2013 10:38 AM
PHP contact form help alfred_e_neuman Programming 10 01-19-2013 01:18 PM
Need a contact form vafe Linux - Software 2 05-23-2007 08:58 AM
Contact form on HTML Gerardoj Linux - General 1 03-26-2004 03:08 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration