LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 10-16-2023, 12:22 PM   #16
Pedroski
Senior Member
 
Registered: Jan 2002
Location: Nanjing, China
Distribution: Ubuntu 20.04
Posts: 2,116

Original Poster
Rep: Reputation: 73

I think I was not clear.

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.
 
Old 10-16-2023, 12:39 PM   #17
Pedroski
Senior Member
 
Registered: Jan 2002
Location: Nanjing, China
Distribution: Ubuntu 20.04
Posts: 2,116

Original Poster
Rep: Reputation: 73
After I ssh in to the cloud server, I see:

Quote:
pedro@ubuntu:~$
But that is just the bash shell, not the domain name.
 
Old 10-16-2023, 01:18 PM   #18
jayjwa
Member
 
Registered: Jul 2003
Location: NY
Distribution: Slackware, Termux
Posts: 798

Rep: Reputation: 256Reputation: 256Reputation: 256
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.

If this is you, it looks like you already have in/outbound mail available: https://www.ionos.com/help/email/gen...ams-imap-pop3/
 
1 members found this post helpful.
Old 10-16-2023, 04:38 PM   #19
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,174
Blog Entries: 1

Rep: Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040
Quote:
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
 
1 members found this post helpful.
Old 10-17-2023, 12:55 AM   #20
Pedroski
Senior Member
 
Registered: Jan 2002
Location: Nanjing, China
Distribution: Ubuntu 20.04
Posts: 2,116

Original Poster
Rep: Reputation: 73
Thanks again for the replies!

@jaywa: I am the culprit! I am the admin!

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.

@bathory I already have my_name@mywebpage.com in the form code, please see below:

Code:
<?php 
session_start();
// name
$q1 = $_POST['cn'];
// contact
$q2 = $_POST['email'];
// message
$q3 = $_POST['message'];
if($q1=='') {
	$_SESSION['error'] = 'You forgot to write your name.';
	header('Location: contact.html.php');	
	}
if($q2=='') {
	$_SESSION['error'] = 'You forgot to write your contact email.';
	header('Location: contact.html.php');
	}
if($q3=='') {
	$_SESSION['error'] = 'You forgot to write your message.';
	header('Location: contact.html.php');
	}
	
$body = "
".$q1."
".$q2."
".$q3."
";

$to1 = "me@foxmail.com";
$subject = $q1 . " message";
$headers = "From: pedro@mywebpage.com\r\n";
$headers .= 'Content-Type: text/plain; charset=utf-8';
mail($to1, $subject, $body, $headers);
// below this PHP is an html success page saying the message has been sent, time and date
?>
I will try your suggestions and post back! Thanks for the tips!
 
Old 10-17-2023, 01:23 AM   #21
Pedroski
Senior Member
 
Registered: Jan 2002
Location: Nanjing, China
Distribution: Ubuntu 20.04
Posts: 2,116

Original Poster
Rep: Reputation: 73
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
#
 
Old 10-17-2023, 02:59 AM   #22
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,174
Blog Entries: 1

Rep: Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040
Quote:
Originally Posted by Pedroski View Post
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)
 
Old 10-17-2023, 12:16 PM   #23
jayjwa
Member
 
Registered: Jul 2003
Location: NY
Distribution: Slackware, Termux
Posts: 798

Rep: Reputation: 256Reputation: 256Reputation: 256
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.

form.html
Code:
<!DOCTYPE html>
<head>
<title>Form submission</title>
</head>
<body>

<form action="mail_handler.php" method="post">
First Name: <input type="text" name="first_name"><br>
Last Name: <input type="text" name="last_name"><br>
Email: <input type="text" name="email"><br>
Message:<br><textarea rows="5" name="message" cols="30"></textarea><br>
<input type="submit" name="submit" value="Submit">
</form>

</body>
</html>
mail_handler.php
Code:
<?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...

?
The script should give you a starting point.
 
Old 10-18-2023, 01:19 AM   #24
Pedroski
Senior Member
 
Registered: Jan 2002
Location: Nanjing, China
Distribution: Ubuntu 20.04
Posts: 2,116

Original Poster
Rep: Reputation: 73
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
 
Old 10-18-2023, 02:02 AM   #25
Pedroski
Senior Member
 
Registered: Jan 2002
Location: Nanjing, China
Distribution: Ubuntu 20.04
Posts: 2,116

Original Poster
Rep: Reputation: 73
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
Or maybe I need to rename the server somehow??
 
Old 10-18-2023, 02:20 AM   #26
Pedroski
Senior Member
 
Registered: Jan 2002
Location: Nanjing, China
Distribution: Ubuntu 20.04
Posts: 2,116

Original Poster
Rep: Reputation: 73
In this

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
#
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
 
Old 10-18-2023, 03:56 AM   #27
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,174
Blog Entries: 1

Rep: Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040
Quote:
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)
 
Old 10-18-2023, 09:59 AM   #28
HytronBG
LQ Newbie
 
Registered: Oct 2023
Posts: 10

Rep: Reputation: 0
Quote:
Originally Posted by jayjwa View Post

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!
 
Old 10-19-2023, 12:49 AM   #29
Pedroski
Senior Member
 
Registered: Jan 2002
Location: Nanjing, China
Distribution: Ubuntu 20.04
Posts: 2,116

Original Poster
Rep: Reputation: 73
@HytronBG

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.
Attached Thumbnails
Click image for larger version

Name:	IONOS_settings.png
Views:	3
Size:	22.6 KB
ID:	41874  

Last edited by Pedroski; 10-19-2023 at 12:53 AM.
 
Old 10-19-2023, 02:46 AM   #30
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,174
Blog Entries: 1

Rep: Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040
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:

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.
 
  


Reply



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
How to set DJ and DS in sendmail.mc rather than sendmail.cf manually anon091 Linux - Software 7 09-02-2014 02:09 PM
Sendmail Sendmail Sendmail lmcilwain Fedora 0 02-14-2006 02:01 PM

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

All times are GMT -5. The time now is 08:14 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