Solved Contact PHP Mail Form..

Rawad

New member
Power User
VIP
Local time
2:03 PM
Messages
532
Hey Guys , anyone here have experience with PHP , especially when it comes to creating a contact form. If you do will you be able to help me with my problem?. I am trying to send mail through my contact form but it's not working for some reason. Every time I click on my contact link I am presented with

2qvsj1s.png

PHP CODE
hastebin

HTML CODE

hastebin
 

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
Acer Aspire M5100
OS
Windows 8.1 64 bit
CPU
Windows 8.1 64-bit
Motherboard
Toshiba L745D
Memory
4096 MB RAM
Graphics Card(s)
Microsoft Basic Display Adapter
Sound Card
High Definition Audio Device
Monitor(s) Displays
1366x768
Screen Resolution
1366x768
Keyboard
Logitech Keyboard K800
Antivirus
MalwareBytes
Browser
Google Chrome

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
ACER ASPIRE 5742G
OS
Microsoft Windows 7 Home Premium 64-bits 7601 Multiprocessor Free Service Pack 1
CPU
Intel(R) Core(TM) i3 CPU M 370 @ 2.40GHz
Motherboard
Acer Aspire 5742G
Memory
4,00 GB
Graphics Card(s)
ATI Mobility Radeon HD 5400 Series
Sound Card
(1) AMD High Definition Audio Device (2) Realtek High Defi
Screen Resolution
1366 x 768 x 32 bits (4294967296 colors) @ 60 Hz
Hard Drives
WDC WD5000BEVT-22ZAT0

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
ACER ASPIRE 5742G
OS
Microsoft Windows 7 Home Premium 64-bits 7601 Multiprocessor Free Service Pack 1
CPU
Intel(R) Core(TM) i3 CPU M 370 @ 2.40GHz
Motherboard
Acer Aspire 5742G
Memory
4,00 GB
Graphics Card(s)
ATI Mobility Radeon HD 5400 Series
Sound Card
(1) AMD High Definition Audio Device (2) Realtek High Defi
Screen Resolution
1366 x 768 x 32 bits (4294967296 colors) @ 60 Hz
Hard Drives
WDC WD5000BEVT-22ZAT0
What html page do you open? I mean http:/localhost/ ..... html
I may not start with file!!

That was the problem, the location I was entering was incorrect which cause the page to load as a text file. Thanks man, although I have errors now. and it's not displaying the $strValidationMessage.I know I am forgetting some mail functions but I don't know exactly what.

errors.png
 

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
Acer Aspire M5100
OS
Windows 8.1 64 bit
CPU
Windows 8.1 64-bit
Motherboard
Toshiba L745D
Memory
4096 MB RAM
Graphics Card(s)
Microsoft Basic Display Adapter
Sound Card
High Definition Audio Device
Monitor(s) Displays
1366x768
Screen Resolution
1366x768
Keyboard
Logitech Keyboard K800
Antivirus
MalwareBytes
Browser
Google Chrome
What errors? Mail is actually sent and recieved? If not check some mail.err and mail.log file.
Also check php.ini : it has some entries like:
SMTP = smtp.somemailserver.com
smtp_port = 25

Copy/paste those lines please to forum (only needed if mail has not been sent succesfully)
 

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
ACER ASPIRE 5742G
OS
Microsoft Windows 7 Home Premium 64-bits 7601 Multiprocessor Free Service Pack 1
CPU
Intel(R) Core(TM) i3 CPU M 370 @ 2.40GHz
Motherboard
Acer Aspire 5742G
Memory
4,00 GB
Graphics Card(s)
ATI Mobility Radeon HD 5400 Series
Sound Card
(1) AMD High Definition Audio Device (2) Realtek High Defi
Screen Resolution
1366 x 768 x 32 bits (4294967296 colors) @ 60 Hz
Hard Drives
WDC WD5000BEVT-22ZAT0
What errors? Mail is actually sent and recieved? If not check some mail.err and mail.log file.
Also check php.ini : it has some entries like:
SMTP = smtp.somemailserver.com
smtp_port = 25

Copy/paste those lines please to forum (only needed if mail has not been sent succesfully)

I Just posted the errors , look at my last post.
 

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
Acer Aspire M5100
OS
Windows 8.1 64 bit
CPU
Windows 8.1 64-bit
Motherboard
Toshiba L745D
Memory
4096 MB RAM
Graphics Card(s)
Microsoft Basic Display Adapter
Sound Card
High Definition Audio Device
Monitor(s) Displays
1366x768
Screen Resolution
1366x768
Keyboard
Logitech Keyboard K800
Antivirus
MalwareBytes
Browser
Google Chrome
I merged the two scripts together. Of course they can't talk to each other... so $strValidationMessage doesn't work.
Also you format to give the form elements a correct name. And some typos.

See attachment for final script (both scripts you posetd merged together). It works (just tested).
Remove line: echo $name.$email.$message;
from source I posted!
 

Attachments

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
ACER ASPIRE 5742G
OS
Microsoft Windows 7 Home Premium 64-bits 7601 Multiprocessor Free Service Pack 1
CPU
Intel(R) Core(TM) i3 CPU M 370 @ 2.40GHz
Motherboard
Acer Aspire 5742G
Memory
4,00 GB
Graphics Card(s)
ATI Mobility Radeon HD 5400 Series
Sound Card
(1) AMD High Definition Audio Device (2) Realtek High Defi
Screen Resolution
1366 x 768 x 32 bits (4294967296 colors) @ 60 Hz
Hard Drives
WDC WD5000BEVT-22ZAT0
I merged the two scripts together. Of course they can't talk to each other... so $strValidationMessage doesn't work.
Also you format to give the form elements a correct name. And some typos.

See attachment for final script (both scripts you posetd merged together). It works (just tested).
Remove line: echo $name.$email.$message;
from source I posted!

awesome it worked but whenever add echo "$strValidationMessage" it gives me an error , I want the text to display if nothing is filled saying Email has to be filled , name has to be filled, etc.

It's giving me and undefined variable .
error.png
 

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
Acer Aspire M5100
OS
Windows 8.1 64 bit
CPU
Windows 8.1 64-bit
Motherboard
Toshiba L745D
Memory
4096 MB RAM
Graphics Card(s)
Microsoft Basic Display Adapter
Sound Card
High Definition Audio Device
Monitor(s) Displays
1366x768
Screen Resolution
1366x768
Keyboard
Logitech Keyboard K800
Antivirus
MalwareBytes
Browser
Google Chrome
Post your contact.php file. Then I test further. It did work on my site!
 

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
ACER ASPIRE 5742G
OS
Microsoft Windows 7 Home Premium 64-bits 7601 Multiprocessor Free Service Pack 1
CPU
Intel(R) Core(TM) i3 CPU M 370 @ 2.40GHz
Motherboard
Acer Aspire 5742G
Memory
4,00 GB
Graphics Card(s)
ATI Mobility Radeon HD 5400 Series
Sound Card
(1) AMD High Definition Audio Device (2) Realtek High Defi
Screen Resolution
1366 x 768 x 32 bits (4294967296 colors) @ 60 Hz
Hard Drives
WDC WD5000BEVT-22ZAT0
It actually does sent an email if all fields are entered? You recieve the mail correctly (check subject, sender etc)?
 

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
ACER ASPIRE 5742G
OS
Microsoft Windows 7 Home Premium 64-bits 7601 Multiprocessor Free Service Pack 1
CPU
Intel(R) Core(TM) i3 CPU M 370 @ 2.40GHz
Motherboard
Acer Aspire 5742G
Memory
4,00 GB
Graphics Card(s)
ATI Mobility Radeon HD 5400 Series
Sound Card
(1) AMD High Definition Audio Device (2) Realtek High Defi
Screen Resolution
1366 x 768 x 32 bits (4294967296 colors) @ 60 Hz
Hard Drives
WDC WD5000BEVT-22ZAT0

Attachments

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
Acer Aspire M5100
OS
Windows 8.1 64 bit
CPU
Windows 8.1 64-bit
Motherboard
Toshiba L745D
Memory
4096 MB RAM
Graphics Card(s)
Microsoft Basic Display Adapter
Sound Card
High Definition Audio Device
Monitor(s) Displays
1366x768
Screen Resolution
1366x768
Keyboard
Logitech Keyboard K800
Antivirus
MalwareBytes
Browser
Google Chrome
Script starts with:

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$to = "[email protected]";
$subject = "New Message";

replace with:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$to = "[email protected]";
$subject = "New Message";
$strValidationMessage = "";

So just add a line. This initializes viariable strValidationMessage. Otherwise it isn't initialized on first load (when you didn't press submit yet).

Post results
 

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
ACER ASPIRE 5742G
OS
Microsoft Windows 7 Home Premium 64-bits 7601 Multiprocessor Free Service Pack 1
CPU
Intel(R) Core(TM) i3 CPU M 370 @ 2.40GHz
Motherboard
Acer Aspire 5742G
Memory
4,00 GB
Graphics Card(s)
ATI Mobility Radeon HD 5400 Series
Sound Card
(1) AMD High Definition Audio Device (2) Realtek High Defi
Screen Resolution
1366 x 768 x 32 bits (4294967296 colors) @ 60 Hz
Hard Drives
WDC WD5000BEVT-22ZAT0
I told you to delete line:
echo $name.$email.$message;
!!!!
 

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
ACER ASPIRE 5742G
OS
Microsoft Windows 7 Home Premium 64-bits 7601 Multiprocessor Free Service Pack 1
CPU
Intel(R) Core(TM) i3 CPU M 370 @ 2.40GHz
Motherboard
Acer Aspire 5742G
Memory
4,00 GB
Graphics Card(s)
ATI Mobility Radeon HD 5400 Series
Sound Card
(1) AMD High Definition Audio Device (2) Realtek High Defi
Screen Resolution
1366 x 768 x 32 bits (4294967296 colors) @ 60 Hz
Hard Drives
WDC WD5000BEVT-22ZAT0
I told you to delete line:
echo $name.$email.$message;
!!!!

same thing happened man. those 3 errors I will send the code by attachment and you test it.
 

Attachments

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
Acer Aspire M5100
OS
Windows 8.1 64 bit
CPU
Windows 8.1 64-bit
Motherboard
Toshiba L745D
Memory
4096 MB RAM
Graphics Card(s)
Microsoft Basic Display Adapter
Sound Card
High Definition Audio Device
Monitor(s) Displays
1366x768
Screen Resolution
1366x768
Keyboard
Logitech Keyboard K800
Antivirus
MalwareBytes
Browser
Google Chrome
And move (not copy):

$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];

To after:
if (isset($_POST['submit']))
{


----------
name,email and message haven't been defined yet (on initial load before clicking submit)
Post results
 

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
ACER ASPIRE 5742G
OS
Microsoft Windows 7 Home Premium 64-bits 7601 Multiprocessor Free Service Pack 1
CPU
Intel(R) Core(TM) i3 CPU M 370 @ 2.40GHz
Motherboard
Acer Aspire 5742G
Memory
4,00 GB
Graphics Card(s)
ATI Mobility Radeon HD 5400 Series
Sound Card
(1) AMD High Definition Audio Device (2) Realtek High Defi
Screen Resolution
1366 x 768 x 32 bits (4294967296 colors) @ 60 Hz
Hard Drives
WDC WD5000BEVT-22ZAT0
Answer #10 please
 

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
ACER ASPIRE 5742G
OS
Microsoft Windows 7 Home Premium 64-bits 7601 Multiprocessor Free Service Pack 1
CPU
Intel(R) Core(TM) i3 CPU M 370 @ 2.40GHz
Motherboard
Acer Aspire 5742G
Memory
4,00 GB
Graphics Card(s)
ATI Mobility Radeon HD 5400 Series
Sound Card
(1) AMD High Definition Audio Device (2) Realtek High Defi
Screen Resolution
1366 x 768 x 32 bits (4294967296 colors) @ 60 Hz
Hard Drives
WDC WD5000BEVT-22ZAT0
I have NOTICE errors disabled. Users like me don't see them. They are only logged in apache.log. That's why I didn't notice them. I do display them in log file and during development
 

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
ACER ASPIRE 5742G
OS
Microsoft Windows 7 Home Premium 64-bits 7601 Multiprocessor Free Service Pack 1
CPU
Intel(R) Core(TM) i3 CPU M 370 @ 2.40GHz
Motherboard
Acer Aspire 5742G
Memory
4,00 GB
Graphics Card(s)
ATI Mobility Radeon HD 5400 Series
Sound Card
(1) AMD High Definition Audio Device (2) Realtek High Defi
Screen Resolution
1366 x 768 x 32 bits (4294967296 colors) @ 60 Hz
Hard Drives
WDC WD5000BEVT-22ZAT0

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
Acer Aspire M5100
OS
Windows 8.1 64 bit
CPU
Windows 8.1 64-bit
Motherboard
Toshiba L745D
Memory
4096 MB RAM
Graphics Card(s)
Microsoft Basic Display Adapter
Sound Card
High Definition Audio Device
Monitor(s) Displays
1366x768
Screen Resolution
1366x768
Keyboard
Logitech Keyboard K800
Antivirus
MalwareBytes
Browser
Google Chrome
mail($to, $subject, $message, "From: " .$name);

must be moved as well:

if($boolValidateOK == 1)
{
mail($to, $subject, $message, "From: " .$name);
$strValidationMessage = "Email Has been Sent.";
}
 

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
ACER ASPIRE 5742G
OS
Microsoft Windows 7 Home Premium 64-bits 7601 Multiprocessor Free Service Pack 1
CPU
Intel(R) Core(TM) i3 CPU M 370 @ 2.40GHz
Motherboard
Acer Aspire 5742G
Memory
4,00 GB
Graphics Card(s)
ATI Mobility Radeon HD 5400 Series
Sound Card
(1) AMD High Definition Audio Device (2) Realtek High Defi
Screen Resolution
1366 x 768 x 32 bits (4294967296 colors) @ 60 Hz
Hard Drives
WDC WD5000BEVT-22ZAT0
Answer #10 please

Yes it says message has been send but I don't actually see the message when I go to my email account. When I go to my contact link this what happens

View attachment 290080

After I enter the info , this what happens , but it doesn't send.

View attachment 290081




<?php if (isset($_POST['submit'])) { $name = $_POST['name']; $email = - Pastebin.com

The code you send me before worked perfect for you while testing?
Yes my tests where fine. All works. still waiting for answer on post #10. Did you read and apply ALL changes I asked you to do?
 

My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
ACER ASPIRE 5742G
OS
Microsoft Windows 7 Home Premium 64-bits 7601 Multiprocessor Free Service Pack 1
CPU
Intel(R) Core(TM) i3 CPU M 370 @ 2.40GHz
Motherboard
Acer Aspire 5742G
Memory
4,00 GB
Graphics Card(s)
ATI Mobility Radeon HD 5400 Series
Sound Card
(1) AMD High Definition Audio Device (2) Realtek High Defi
Screen Resolution
1366 x 768 x 32 bits (4294967296 colors) @ 60 Hz
Hard Drives
WDC WD5000BEVT-22ZAT0
Back
Top