Pay Pal Form

Hi there I have a form that sends the input to my email the form also uploads an image to my email.
I want to send the form as normal to my email but i also want to then send a paypal bun now link automatically.

So a user fills out the form which i get the results and once form submitted to me it then redirects to pay pal for payment.

Code for form.

<?php
require_once 'submit.php';
?>

<link href="/vibracart/vcpopup.css" rel="stylesheet" type="text/css">
<script src="https://js.stripe.com/v3/"></script>

<div id="wrapper">

<hr width="100%" color="#000000">
 
    <div class="form-wrapper">
        <form method="post" action="" enctype="multipart/form-data" class="animate-form">

            <h4 class="headt">Image Upload.</h4>
            
             <!-- Display submission status -->
            <?php if(!empty($statusMsg)){ ?>
                <p class="statusMsg <?php echo !empty($msgClass)?$msgClass:''; ?>"><?php echo $statusMsg; ?></p>
            <?php } ?>
            
            <!-- Contact form -->
            <div class="form-group">
            <p>Your Name:</p>
                <input type="text" name="name" class="form-control" value="<?php echo !empty($postData['name'])?$postData['name']:''; ?>">
            </div>
            <div class="form-group">
            <p>Your Pay Pal E Mail:</p>
                <input type="email" name="email" class="form-control" value="<?php echo !empty($postData['email'])?$postData['email']:''; ?>">
            </div>

            <div class="form-group">
            <p>Name To Be Used On Cushion:</p>
                <input type="text" name="name1" class="form-control" value="<?php echo !empty($postData['name1'])?$postData['name1']:''; ?>">
            </div>

            <div class="form-group">
            <p>Year Born: (E.G. 1961)</p>
                <input type="text" name="born" class="form-control" value="<?php echo !empty($postData['born'])?$postData['born']:''; ?>">
            </div>

            <div class="form-group">
            <p>Year Passed: (e.g. 2023)</p>
                <input type="text" name="passed" class="form-control" value="<?php echo !empty($postData['passed'])?$postData['passed']:''; ?>">
            </div>

            <div class="form-group">
                <input type="hidden" name="subject" class="form-control" value="Image Uploaded">
            </div>
            <div class="form-group">
                <input type="hidden" name="message" class="form-control" value="Please Use This Image For My Cushion.">
            </div>
            <p>Image To Be Used On Cushion.</p>
            <div class="form-group">
                <input type="file" name="attachment" class="form-control">
            </div>
            <div class="submit">
                <input type="submit" name="submit" class="btn" value="SUBMIT">
            </div>
        </form>
    </div>	
</div>
<?php
include('inc/footer.php');
?>

The submit.php code

<?php

<br>

// Email settings<?php

include('inc/footer.php');

?>

$toEmail ='myemail'; // Recipient email
$from = 'myemail'; // Sender email
$fromName = 'My Store'; // Sender name

// File upload settings
$attachmentUploadDir = "uploads/";
$allowFileTypes = array('pdf', 'doc', 'docx', 'jpg', 'png', 'gif', 'jpeg');

/* Form submission handler code */
$postData = $uploadedFile = $statusMsg = $valErr = '';
$msgClass = 'errordiv';
if(isset($_POST['submit'])){
    // Get the submitted form data
    $postData = $_POST;
    $name = trim($_POST['name']);
    $email = trim($_POST['email']);
    $subject = trim($_POST['subject']);
    $message = trim($_POST['message']);
    $name1 = trim($_POST['name1']);
    $born = trim($_POST['born']);
    $passed = trim($_POST['passed']);

    // Validate input data
    if(empty($name)){
        $valErr .= 'Please enter your name.<br/>';
    }
    if(empty($email) || filter_var($email, FILTER_VALIDATE_EMAIL) === false){
        $valErr .= 'Please enter a valid email.<br/>';
    }
    if(empty($subject)){
        $valErr .= 'Please enter subject.<br/>';
    }
    if(empty($message)){
        $valErr .= 'Please enter message.<br/>';
    }
    
    // Check whether submitted data is valid
    if(empty($valErr)){
        $uploadStatus = 1;
        
        // Upload attachment file
        if(!empty($_FILES["attachment"]["name"])){
            
            // File path config
            $targetDir = $attachmentUploadDir;
            $fileName = basename($_FILES["attachment"]["name"]);
            $targetFilePath = $targetDir . $fileName;
            $fileType = pathinfo($targetFilePath, PATHINFO_EXTENSION);
            
            // Allow certain file formats
            if(in_array($fileType, $allowFileTypes)){
                // Upload file to the server
                if(move_uploaded_file($_FILES["attachment"]["tmp_name"], $targetFilePath)){
                    $uploadedFile = $targetFilePath;
                }else{
                    $uploadStatus = 0;
                    $statusMsg = "Sorry, there was an error uploading your file.";
                }
            }else{
                $uploadStatus = 0;
                $statusMsg = 'Sorry, only '.implode('/', $allowFileTypes).' files are allowed to upload.';
            }
        }
        
        if($uploadStatus == 1){
            // Email subject
            $emailSubject = 'Image Upload Submitted By '.$name;
            
            // Email message 
            $htmlContent = '<h2>Image Upload Submitted</h2>
                <p><b>Name:</b> '.$name.'</p>
                <p><b>Email:</b> '.$email.'</p>
                <p><b>Subject:</b> '.$subject.'</p>
                <p><b>Message:</b><br/>'.$message.'</p>
                <p><b>Name On Cushion:</b><br/>'.$name1.'</p>
                <p><b>Date Born:</b><br/>'.$born.'</p>
                <p><b>Date Passed:</b><br/>'.$passed.'</p>';
            
            // Header for sender info
            $headers = "From: $fromName"." <".$from.">";

            // Add attachment to email
            if(!empty($uploadedFile) && file_exists($uploadedFile)){
                
                // Boundary 
                $semi_rand = md5(time()); 
                $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; 
                
                // Headers for attachment 
                $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; 
                
                // Multipart boundary 
                $message = "--{$mime_boundary}\n" . "Content-Type: text/html; charset=\"UTF-8\"\n" .
                "Content-Transfer-Encoding: 7bit\n\n" . $htmlContent . "\n\n"; 
                
                // Preparing attachment
                if(is_file($uploadedFile)){
                    $message .= "--{$mime_boundary}\n";
                    $fp =    @fopen($uploadedFile,"rb");
                    $data =  @fread($fp,filesize($uploadedFile));
                    @fclose($fp);
                    $data = chunk_split(base64_encode($data));
                    $message .= "Content-Type: application/octet-stream; name=\"".basename($uploadedFile)."\"\n" . 
                    "Content-Description: ".basename($uploadedFile)."\n" .
                    "Content-Disposition: attachment;\n" . " filename=\"".basename($uploadedFile)."\"; size=".filesize($uploadedFile).";\n" . 
                    "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
                }
                
                $message .= "--{$mime_boundary}--";
                $returnpath = "-f" . $email;
                
                // Send email
                $mail = mail($toEmail, $emailSubject, $message, $headers, $returnpath);
                
                // Delete attachment file from the server
                @unlink($uploadedFile);
            }else{
                    // Set content-type header for sending HTML email
                $headers .= "\r\n". "MIME-Version: 1.0";
                $headers .= "\r\n". "Content-type:text/html;charset=UTF-8";
                
                // Send email
                $mail = mail($toEmail, $emailSubject, $htmlContent, $headers); 
            }
            
            // If mail sent
            if($mail){
                $statusMsg = '<b>Thanks!<br> Your Personalised Cushion Order Has Been Submitted Successfully.<br><br> We Will Shortly Send You A Payment Request.</b>';
                $msgClass = 'succdiv';
                
                $postData = '';
            }else{
                $statusMsg = 'Failed! Something went wrong, please try again.';
            }
        }
    }else{
        $valErr = !empty($valErr)?'<br/>'.trim($valErr, '<br/>'):'';
        $statusMsg = 'Please fill all the mandatory fields.'.$valErr;
    }
}
?>

To post code on the forum, use either bbcode [code][/code] tags or markdown three back-ticks ```, on their own lines before/after the code. I have edited your post above.

Sponsor our Newsletter | Privacy Policy | Terms of Service