Linux - SoftwareThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
This thread started as a question about getting sendmail to send the contents of an html form from my home laptop. However, that seems troublesome and is not important.
Now, I would like my contact form to work from my webpage, which is a so-called cloud server hosted by IONOS.
On my last little cloud server, which was based in China, my html form worked well, but I can't remember how I did that now.
I don't really want to receive email on the little cloud server, just send email using php. I would just like to be able to send an email from my webpage to my email at qq.com
I have a DNS entry for my webpage which maps www.mywebpage.com to my ipv4 number assigned by the host company IONOS. I believe that is a so-called FQDN???
So I think maybe I need to use this ipv4 number in order to get emails relayed via smtp.qq.com.
Whoever setup PHP on the server will set the mail binary in php.ini. This is usually sendmail. This could be you for your own install or, if you are using someone else's server, that would be the server admin there. If you are setting up your own mailserver, you need a fqdn hostname, set up a mailserver via its config files, and be reachable on the internet. If you are using someone else's server they should have already done this (as long as the service allows mail). As long as the setup is working, https://stackoverflow.com/questions/...ng-php#5335311.
From the cloud server, the first thing I'd do is test mail using /usr/bin/mailx (or similar client) to make sure mail works. Only then try it via PHP scripting. If that doesn't work, ask the cloud server admin if outgoing mail is OK, and if you can setup a mailserver.
I don't really want to receive email on the little cloud server, just send email using php. I would just like to be able to send an email from my webpage to my email at qq.com
I have a DNS entry for my webpage which maps www.mywebpage.com to my ipv4 number assigned by the host company IONOS. I believe that is a so-called FQDN???
So I think maybe I need to use this ipv4 number in order to get emails relayed via smtp.qq.com.
The mail you want your server to send after filling the form must use a From address like name@mywebpage.com and not www-data@ubuntu
For this you need to setup a few things:
Code:
1. Edit /etc/hosts
x.x.x.x www.mywebpage.com mywebpage.com #x.x.x.x is your ipv4 address
127.0.0.1 www.mywebpage.com mywebpage.com localhost localhost.localdomain
2. Use masquerading (see my post #8 above)
3. If the 2 things above don't help edit directly sendmail.cf (make a backup copy first), find the line #Dj$w.Foo.COM and change it to:
Dj$w.mywebpage.com
4. Edit the form code so the sender address will be name@mywebpage.com instead of www-data@ubuntu used by the webserver
This little cloud server is a very basic Ubuntu 22.04 Server set-up. IONOS did not pre-install anything. I had to install apache2, mysql, php and sendmail! I even had to install the php module to interact with apache2 separately!
There was no php.ini on the server anywhere!
When I have time I will try to get phpMyAdmin working!
I want to know how to get these things running, because, previously, I had webpage hosting for my webpage. If there is a problem, you need to write a ticket, wait, maybe get an answer, so I thought it is better to be the admin! But I don't really have the correct knowledge.
Could you please tell me what this means? I believe, changes I make to hosts as sudo will not persist.
This is at the top of /etc/hosts on the cloud server
Quote:
# Your system has configured 'manage_etc_hosts' as True.
# As a result, if you wish for changes to this file to persist
# then you will need to either
# a.) make changes to the master file in /etc/cloud/templates/hosts.debian.tmpl
# b.) change or remove the value of 'manage_etc_hosts' in
# /etc/cloud/cloud.cfg or cloud-config from user-data
#
Could you please tell me what this means? I believe, changes I make to hosts as sudo will not persist.
This is at the top of /etc/hosts on the cloud server
# Your system has configured 'manage_etc_hosts' as True.
# As a result, if you wish for changes to this file to persist
# then you will need to either
# a.) make changes to the master file in /etc/cloud/templates/hosts.debian.tmpl
# b.) change or remove the value of 'manage_etc_hosts' in
# /etc/cloud/cloud.cfg or cloud-config from user-data
#
Follow the instructions then... They are pretty straight forward!
Just edit /etc/cloud/templates/hosts.debian.tmpl and add there the hostnames you want.
(Or you can select the 2nd option and comment out manage_etc_hosts in /etc/cloud/cloud.cfg)
If you are the admin that you have to do it all. I seems we have 3 problems to fix, in order:
1) Set up your mailserver and make sure it works with basic mailing before you go further. To test, mail a host that you know will not bounce you.
Code:
mailx -s "Test of mail from Linux to Solaris" jayjwa@kulve.lan
To: jayjwa@kulve.lan
Subject: Test of mail from Linux to Solaris
As it says in the subject...
^D
-------
(Preliminary) Envelope contains:
To: jayjwa@kulve.lan
Subject: Test of mail from Linux to Solaris
Send this message [yes/no, empty: recompose]? yes
I think we already posted the configs for Sendmail earlier in the thread.
2) Make sure your webserver is parsing PHP. Write a small script that just calls phpinfo(). Access it from a web browser and see that it works. You can find default php.ini online but maybe you don't need one. Only after all this works continue.
3) Add web forms and script. Here's an example I found. It worked when I tested it here, but a copy of the mail added my fqdn to my already fqdn that landed back in the sending host's root mailbox (I have "apache" aliased to "root" here). That might be my mistake in Sendmail setup or maybe the script. However, the mail got sent.
<?php
if(isset($_POST['submit'])){
$to = "jayjwa@kulve.lan"; // this is your Email address
$from = $_POST['email']; // this is the sender's Email address
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$subject = "Form submission";
$subject2 = "Copy of your form submission";
$message = $first_name . " " . $last_name . " wrote the following:" . "\n\n" . $_POST['message'];
$message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['message'];
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
// You can also use header('Location: thank_you.php'); to redirect to another page.
// You cannot use header and echo together. It's one or the other.
}
?>
On the target host:
Code:
Last login: Wed Oct 11 20:14:55 from atr2
Sun Microsystems Inc. SunOS 5.9 Generic May 2002
You have new mail.
[12:57 jayjwa@kulve:~ >] mailx [pts/5 hst:1]
mailx version 5.0 Sat Apr 6 14:57:29 PST 2002 Type ? for help.
"/var/mail/jayjwa": 2 messages 2 new
>N 1 jayjwa Tue Oct 17 12:42 22/917 Test of mail from Linux t
N 2 jayjwa Tue Oct 17 12:54 23/886 Form submission
? type 2
Message 2:
From apache@a.b.c Tue Oct 17 12:54:06 2023
Date: Tue, 17 Oct 2023 12:54:05 -0400
To: jayjwa@kulve.lan
Subject: Form submission
From: jayjwa@a.b.c
jayjwa jayjwa wrote the following:
I sure hope this works...
?
I checked this morning and my changes to /etc/hosts are still there!
I did not edit any other file.
/etc/hosts on the cloud server:
Quote:
# Your system has configured 'manage_etc_hosts' as True.
# As a result, if you wish for changes to this file to persist
# then you will need to either
# a.) make changes to the master file in /etc/cloud/templates/hosts.debian.tmpl
# b.) change or remove the value of 'manage_etc_hosts' in
# /etc/cloud/cloud.cfg or cloud-config from user-data
#
#127.0.1.1 ubuntu ubuntu
#127.0.0.1 localhost
# x.x.x.x www.mywebpage.com mywebpage.com #x.x.x.x is your ipv4 address
195.20.254.33 www.mywebpage mywebpage
# 127.0.0.1 www.mywebpage.com mywebpage.com localhost localhost.localdomain
127.0.0.1 www.mywebpage mywebpage localhost localhost.localdomain
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
Not sure what to put for hostname in this file: /etc/cloud/templates/hosts.debian.tmpl
Should I change hostname for mywebpage.com or just mywebpage??
Do I need to do anything with the ip6 part???
Do I need to put manage_etc_hosts: True in the file on its own line??
Quote:
## template:jinja
{#
This file (/etc/cloud/templates/hosts.debian.tmpl) is only utilized
if enabled in cloud-config. Specifically, in order to enable it
you need to add the following to config:
manage_etc_hosts: True
-#}
# Your system has configured 'manage_etc_hosts' as True.
# As a result, if you wish for changes to this file to persist
# then you will need to either
# a.) make changes to the master file in /etc/cloud/templates/hosts.debian.tmpl
# b.) change or remove the value of 'manage_etc_hosts' in
# /etc/cloud/cloud.cfg or cloud-config from user-data
#
{# The value '{{hostname}}' will be replaced with the local-hostname -#}
127.0.1.1 {{fqdn}} {{hostname}}
127.0.0.1 localhost
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
# Your system has configured 'manage_etc_hosts' as True.
# As a result, if you wish for changes to this file to persist
# then you will need to either
# a.) make changes to the master file in /etc/cloud/templates/hosts.debian.tmpl
# b.) change or remove the value of 'manage_etc_hosts' in
# /etc/cloud/cloud.cfg or cloud-config from user-data
#
Where might I find this:
Quote:
cloud-config from user-data
This below is from /etc/cloud/templates/hosts.debian.tmpl
The modules mentioned in cloud_init_modules include: update_hostname and update_etc_hosts, but I don't think they are working, because sendmail still thinks the hostname is ubuntu.
Nevertheless preserve_hostname is set to false.
Quote:
# This will cause the set+update hostname module to not operate (if true)
preserve_hostname: false
# If you use datasource_list array, keep array items in a single line.
# If you use multi line array, ds-identify script won't read array items.
# Example datasource config
# datasource:
# Ec2:
# metadata_urls: [ 'blah.com' ]
# timeout: 5 # (defaults to 50 seconds)
# max_wait: 10 # (defaults to 120 seconds)
# The modules that run in the 'init' stage
cloud_init_modules:
- migrator
- seed_random
- bootcmd
- write_files
- growpart
- resizefs
- disk_setup
- mounts
- set_hostname
- update_hostname
- update_etc_hosts
- ca_certs
- rsyslog
- users_groups
- ssh
I checked this morning and my changes to /etc/hosts are still there!
I did not edit any other file.
/etc/hosts on the cloud server:
# Your system has configured 'manage_etc_hosts' as True.
# As a result, if you wish for changes to this file to persist
# then you will need to either
# a.) make changes to the master file in /etc/cloud/templates/hosts.debian.tmpl
# b.) change or remove the value of 'manage_etc_hosts' in
# /etc/cloud/cloud.cfg or cloud-config from user-data
#
#127.0.1.1 ubuntu ubuntu
#127.0.0.1 localhost
# x.x.x.x www.mywebpage.com mywebpage.com #x.x.x.x is your ipv4 address
195.20.254.33 www.mywebpage mywebpage
# 127.0.0.1 www.mywebpage.com mywebpage.com localhost localhost.localdomain
127.0.0.1 www.mywebpage mywebpage localhost localhost.localdomain
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
Are you sure that these settings survive a reboot?
If they do, you don't need to change anything in the other files.
Re. ipv6, if you own an ipv6 address use the same hostname(s) as for the ipv4 address(es)
The second issue is as stated, almost all mailservers using block lists (almost all of them) will block you unless you are using Gmail or another mega-provider. You can thank Spamhaus and the other over-zealous outfits like them for making email virtually unusable by us little people.
This can be resolved by using TXT record if you host your own DNS. I have been using my own sendmail and my own domain since 1999 and it is still functional. What you have to do is create a TXT record in the DNS and specify the IP of the email servers that are responsible for sending out email for your domain. For example for the domain mydomain.net:
mydomain.net. IN TXT "v=spf1 mx ip4:<ipv4_address> ip6:<ipv6_address> ~all"
This works for me and never have email rejected by any other providers. I do have a static IPv4 just to mention, but that is not very difficult to get. I disagree to use gmail or any of the giant providers! Just dont trust them!
I rent this cloud server space from IONOS, I have a static ip.
I don't think I own my own DNS. Attached is a screenshot of the some of the settings for my domain in my account at IONOS.
Funnily enough, I had an email from them today: "You haven't set up your email yet." And a link to my account where I should do that.
But I am not sure that will help me using PHP to send the contents of an html form using PHP.
It can't be rocket science to make the html form and PHP send an email!
I attach a picture of some of the settings for my domain at IONOS. Is that the TXT setting you mean?
I am trying to send the contact message to my qq mail, but that is not important. I could send it to my mail at IONOS when if I set that up, I suppose.
I could save the message and sender in MySQL, I know how to do that! I just thought email would be easy!
@bathory:
Quote:
Are you sure that these settings survive a reboot?
They don't survive a reboot! I just checked /etc/hosts, updated and upgraded, then rebooted. When I looked at /etc/hosts again, it was back to:
Quote:
127.0.1.1 ubuntu ubuntu
127.0.0.1 localhost
I did not know it would only change on reboot, I thought it would be reread daily.
Are you sure that these settings survive a reboot?
They don't survive a reboot! I just checked /etc/hosts, updated and upgraded, then rebooted. When I looked at /etc/hosts again, it was back to:
127.0.1.1 ubuntu ubuntu
127.0.0.1 localhost
I did not know it would only change on reboot, I thought it would be reread daily.
So you need to follow the instructions in /etc/hosts...
I don't use ubuntu but if I gad to choose, I would comment out the following line in /etc/cloud/cloud.cfg
Code:
#-update_etc_hosts
Then reboot and see if your changes in /etc/hosts survive.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.